title: Simple link to show a hidden field in a rails 3 app using link_to_remote
body: <p>I have a form that works, but I need to have some fields hidden unless the user clicks a link. Once they are exposed, everything is good.  Here is the partial responsible for the form:</p>
  
  <pre><code> &lt;%= fields_for :city do |builder| %&gt;
  &lt;p class="fields&gt;
      &lt;%= builder.label :name, "City" %&gt;
      &lt;%= builder.hidden_field :name %&gt;&lt;br /&gt;
      &lt;%= builder.label :state, "State" %&gt;
      &lt;%= builder.text_field :state %&gt;
      &lt;%= link_to_function "new city", "show_fields('city_name')" %&gt;
  &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Then in application.js</p>
  
  <pre><code> function show_fields(link) {  
      $(link).previous("input[type=hidden]").show;
  }  
  </code></pre>
  
  <p>When I try to run that and inspect it in chrome, I see the following error:</p>
  
  <p>application.js4:Uncaught TypeError:Object# has no method 'previous'</p>
  
  <p>Now, I admit I am totally new to js and still pretty new to ruby and rails, but I am pretty sure I am doing exactly what Ryan Bates did in one of the <a href="http://asciicasts.com/episodes/197-nested-model-form-part-2" rel="nofollow">railscasts</a>. (I have tried the show_fields(this) format too with the same result).</p>
  
  <p>What is the correct way to target my hidden_field with a link that exposes it?  This seems so simple, but I can't figure out why the previous method doesn't work.  Sorry if this is obvious, but I seriously can't find the right place to start.</p>