Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 8b99df826c3b6cf56a1caaae5f931d50 > files > 433

ruby-actionpack-2.3.4-1mdv2010.0.noarch.rpm

<?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
  &lt;% div_for(post) do %&gt;     &lt;div id=&quot;post_45&quot; class=&quot;post&quot;&gt;
    &lt;%= post.body %&gt;           What a wonderful world!
  &lt;% end %&gt;                  &lt;/div&gt;

  # 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>&nbsp;&nbsp;
      <a href="#M000120">dom_id</a>&nbsp;&nbsp;
      <a href="#M000118">partial_path</a>&nbsp;&nbsp;
      <a href="#M000121">plural_class_name</a>&nbsp;&nbsp;
      <a href="#M000122">singular_class_name</a>&nbsp;&nbsp;
      </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)   # =&gt; &quot;post&quot;
  dom_class(Person) # =&gt; &quot;person&quot;
</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)   # =&gt; &quot;edit_post&quot;
  dom_class(Person, :edit) # =&gt; &quot;edit_person&quot;
</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
&quot;new_&quot; instead. Examples:
</p>
<pre>
  dom_id(Post.find(45))       # =&gt; &quot;post_45&quot;
  dom_id(Post.new)            # =&gt; &quot;new_post&quot;
</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) # =&gt; &quot;edit_post_45&quot;
</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)                   # =&gt; &quot;posts/post&quot;
  partial_path(Person)                 # =&gt; &quot;people/person&quot;
  partial_path(Person, &quot;admin/games&quot;)  # =&gt; &quot;admin/people/person&quot;
</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)             # =&gt; &quot;posts&quot;
  plural_class_name(Highrise::Person) # =&gt; &quot;highrise_people&quot;
</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)             # =&gt; &quot;post&quot;
  singular_class_name(Highrise::Person) # =&gt; &quot;highrise_person&quot;
</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>