ActiveRecord::DomId =================== An action-model_id convention for Active Record dom ids. Models are underscored and suffixed with their _id or _new. The hyphen-prefixed action is optional. class RepoMan < ActiveRecord::Base end # collection assert_equal 'repo_men', RepoMan.dom_id # new instance in collection assert_equal 'repo_man_new', RepoMan.new.dom_id assert_equal 'hire-repo_man_new', RepoMan.new.dom_id(:hire) # ordinary instance assert_equal 'repo_man_1', RepoMan.find(1).dom_id assert_equal 'edit-repo_man_1', RepoMan.find(1).dom_id(:edit) Other classes can keep a consistent action-entity_id pattern: class Cart # assert_equal 'cart', Cart.new.dom_id # assert_equal 'edit-cart', Cart.new.dom_id(:edit) def dom_id(action = nil) action ? "#{action}-cart" : 'cart' end end Inspired by Jamis Buck's AR::B#dom_id.