title: How do you get the Ruby on Rails generated id of a form element for reference in JavaScript?
body: <p>When using the <code>form_for</code> helper and a <code>text_field</code> call, Ruby on Rails will generate a unique id for the <code>&lt;input /&gt;</code> element that it outputs. How can I generate the same id for later inclusion into JavaScript generated later?</p>
  
  <pre><code>&lt;%= form_for @user do |f| %&gt;
    &lt;%= f.text_field :username %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Then later in the page:</p>
  
  <pre><code>&lt;%= javascript_tag do %&gt;
    $('&lt;%= id of the :username field %&gt;').doSomethingReallyCool();
  &lt;% end %&gt;
  </code></pre>