Module

RecordIdentifier

The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or Active Resources or pretty much any other model type that has an id. These patterns are then used to try elevate the view actions to a higher logical level. Example:

# routes
map.resources :posts

# view
<% div_for(post) do %>     <div>
  <%= post.body %>           What a wonderful world!
<% end %>                  </div>

# controller
def destroy
  post = Post.find(params[:id])
  post.destroy

  respond_to do |format|
    format.html { redirect_to(post) } # Calls polymorphic_url(post) which in turn calls post_url(post)
    format.js do
      # Calls: new Effect.fade('post_45');
      render(:update) { |page| page[post].visual_effect(:fade) }
    end
  end
end

As the example above shows, you can stop caring to a large extent what the actual id of the post is. You just know that one is being assigned and that the subsequent calls in redirect_to and the RJS expect that same naming convention and allows you to write less code if you follow it.

Public Methods
dom_class The DOM class convention is to use the singular form of an object or class. Examples:
dom_id The DOM id convention is to use the singular form of an object or class with the id following an underscore. If no id is found, prefix with "new_" instead. Examples:
partial_path Returns plural/singular for a record or class. Example:
plural_class_name Returns the plural class name of a record or class. Examples:
singular_class_name Returns the singular class name of a record or class. Examples:
Private Methods
class_from_record_or_class
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.