<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Module: ActionController::RecordIdentifier</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript"> // <![CDATA[ function popupCode( url ) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } function toggleCode( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // Make codeblocks hidden by default document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) // ]]> </script> </head> <body> <div id="classHeader"> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Module</strong></td> <td class="class-name-in-header">ActionController::RecordIdentifier</td> </tr> <tr class="top-aligned-row"> <td><strong>In:</strong></td> <td> <a href="../../files/lib/action_controller/record_identifier_rb.html"> lib/action_controller/record_identifier.rb </a> <br /> </td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> <div id="description"> <p> The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or Active <a href="Resources.html">Resources</a> 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: </p> <pre> # routes map.resources :posts # view <% div_for(post) do %> <div id="post_45" class="post"> <%= 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 </pre> <p> 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. </p> </div> </div> <div id="method-list"> <h3 class="section-bar">Methods</h3> <div class="name-list"> <a href="#M000119">dom_class</a> <a href="#M000120">dom_id</a> <a href="#M000118">partial_path</a> <a href="#M000121">plural_class_name</a> <a href="#M000122">singular_class_name</a> </div> </div> </div> <!-- if includes --> <div id="section"> <div id="constants-list"> <h3 class="section-bar">Constants</h3> <div class="name-list"> <table summary="Constants"> <tr class="top-aligned-row context-row"> <td class="context-item-name">JOIN</td> <td>=</td> <td class="context-item-value">'_'.freeze</td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">NEW</td> <td>=</td> <td class="context-item-value">'new'.freeze</td> </tr> </table> </div> </div> <!-- if method_list --> <div id="methods"> <h3 class="section-bar">Public Instance methods</h3> <div id="method-M000119" class="method-detail"> <a name="M000119"></a> <div class="method-heading"> <a href="RecordIdentifier.src/M000119.html" target="Code" class="method-signature" onclick="popupCode('RecordIdentifier.src/M000119.html');return false;"> <span class="method-name">dom_class</span><span class="method-args">(record_or_class, prefix = nil)</span> </a> </div> <div class="method-description"> <p> The DOM class convention is to use the singular form of an object or class. Examples: </p> <pre> dom_class(post) # => "post" dom_class(Person) # => "person" </pre> <p> If you need to address multiple instances of the same class in the same view, you can prefix the <a href="RecordIdentifier.html#M000119">dom_class</a>: </p> <pre> dom_class(post, :edit) # => "edit_post" dom_class(Person, :edit) # => "edit_person" </pre> </div> </div> <div id="method-M000120" class="method-detail"> <a name="M000120"></a> <div class="method-heading"> <a href="RecordIdentifier.src/M000120.html" target="Code" class="method-signature" onclick="popupCode('RecordIdentifier.src/M000120.html');return false;"> <span class="method-name">dom_id</span><span class="method-args">(record, prefix = nil)</span> </a> </div> <div class="method-description"> <p> 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: </p> <pre> dom_id(Post.find(45)) # => "post_45" dom_id(Post.new) # => "new_post" </pre> <p> If you need to address multiple instances of the same class in the same view, you can prefix the <a href="RecordIdentifier.html#M000120">dom_id</a>: </p> <pre> dom_id(Post.find(45), :edit) # => "edit_post_45" </pre> </div> </div> <div id="method-M000118" class="method-detail"> <a name="M000118"></a> <div class="method-heading"> <a href="RecordIdentifier.src/M000118.html" target="Code" class="method-signature" onclick="popupCode('RecordIdentifier.src/M000118.html');return false;"> <span class="method-name">partial_path</span><span class="method-args">(record_or_class, controller_path = nil)</span> </a> </div> <div class="method-description"> <p> Returns plural/singular for a record or class. Example: </p> <pre> partial_path(post) # => "posts/post" partial_path(Person) # => "people/person" partial_path(Person, "admin/games") # => "admin/people/person" </pre> </div> </div> <div id="method-M000121" class="method-detail"> <a name="M000121"></a> <div class="method-heading"> <a href="RecordIdentifier.src/M000121.html" target="Code" class="method-signature" onclick="popupCode('RecordIdentifier.src/M000121.html');return false;"> <span class="method-name">plural_class_name</span><span class="method-args">(record_or_class)</span> </a> </div> <div class="method-description"> <p> Returns the plural class name of a record or class. Examples: </p> <pre> plural_class_name(post) # => "posts" plural_class_name(Highrise::Person) # => "highrise_people" </pre> </div> </div> <div id="method-M000122" class="method-detail"> <a name="M000122"></a> <div class="method-heading"> <a href="RecordIdentifier.src/M000122.html" target="Code" class="method-signature" onclick="popupCode('RecordIdentifier.src/M000122.html');return false;"> <span class="method-name">singular_class_name</span><span class="method-args">(record_or_class)</span> </a> </div> <div class="method-description"> <p> Returns the singular class name of a record or class. Examples: </p> <pre> singular_class_name(post) # => "post" singular_class_name(Highrise::Person) # => "highrise_person" </pre> </div> </div> </div> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> </div> </body> </html>