I have this :
<% f.fields_for :permits do |permit| %>
<tr>
<td><%= permit.access.name%></td>
<td><center><%= permit.check_box :create %></center></td>
<td><center><%= permit.check_box :edit %></center></td>
<td><center><%= permit.check_box :_destroy %></center></td>
</tr>
<% end %>
Where @Group has_many :permits
and permit has_one :access
, all classes have attr_accessor
.
Then I tried to print the name of access 开发者_Python百科(<%= permit.access.name%>
), but i get this error:
undefined method `access' for #<ActionView::Helpers::FormBuilder:0x3e3cce8>
How I can get the object var's into fields_for ?
from already thank you very much
Try using permit.object.access.name
. permit
is the form object. permit.object
is the instance of your Permit model.
精彩评论