title: Fields_for with nested attribute, has_many through association
body: <p>I have 3 models - <strong>standards</strong>, <strong>layers</strong>, and <strong>layers_assocs</strong>. Standards has many layers through layer_assocs and the rest is trivial. The <strong>layers_assocs</strong> table stores the <code>standards_id</code>, <code>layer_id</code> and a <code>visible</code> boolean while the <strong>layers</strong> table is just a look up table with <code>name</code> (and auto-increment <code>id</code>).</p>
  
  <p>On the standards options page, I have a check box which updates the <code>:visible</code> nested attribute. I'm looking for a way to show the associated layer name in a form label. Currently, I have this for the check box:</p>
  
  <pre><code>&lt;%= f.fields_for :layers_assocs do |assoc| %&gt;
    &lt;%= assoc.check_box :visible %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>How I would display the associated layer name with the <strong>layers_assocs</strong> <code>belongs_to</code> <strong>layers</strong> association is a mystery. I can display <code>layer_id</code> with this</p>
  
  <pre><code>&lt;%= assoc.text_field :layer_id %&gt;
  </code></pre>
  
  <p>But trying to use that as an integer for displaying name through layers like <code>standard.layers[assoc.layer_id]</code> or <code>standard.layers[:layer_id]</code> doesn't fly. <code>assoc</code> is a FormBuilder object so I'm not sure what to do. Inspecting <code>assoc</code> spits out a <em>huge</em> object with everything in the standard.</p>
  
  <p>I've checked the <a href="http://apidock.com/rails/ActionView/Helpers/FormHelper/fields_for" rel="nofollow noreferrer">rails api on <code>fields_for</code></a> and <a href="https://stackoverflow.com/questions/4853373/rails-fields-for-with-index">this question</a> with no luck. Either <code>:name</code> or <code>:visible</code> is undefined.</p>