ActiveRecord DOM IDs
Here’s a very simple implementation that I use in my projects, courtesy of Jamis Buck:
class ActiveRecord::Base def dom_id(prefix=nil) display_id = new_record? ? "new" : id prefix ||= self.class.name.underscore prefix != :bare ? "#{prefix.to_s.dasherize}-#{display_id}" : display_id end endSo, you can do stuff like this in your views: <ul> <% @entries.each do |entry| %>> <%= entry.body %> <% end %> And stuff like this in your controller: def remove_entry entry = JournalEntry.find(params[:id]) update_page do |page| page[entry.dom_id].remove end end