开发者

How I can access into a Object in a view nested form_for?

开发者 https://www.devze.com 2023-03-22 12:50 出处:网络
I have this : <% f.fields_for :permits do |permit| %> <tr> <td><%= permit.access.name%></td>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消