开发者

Collections and Nested Attribute Forms

开发者 https://www.devze.com 2023-02-23 00:35 出处:网络
Assume I have the models Foo and Bar, where Bar is a nested attribute of Foo. <%= form_for @foo do |f| %>

Assume I have the models Foo and Bar, where Bar is a nested attribute of Foo.

<%= form_for @foo do |f| %>
 <%= f.fields_for :bars do |builder| %>
   <%= render 'bar_fields', :f => builder %>
 <% end %>  
 <%= f.submit %>
<% end %>

The partial bar_fields has the fields that correspond to the attributes in Bar. I only want to edit certain 开发者_运维知识库fields in this model, so I've left out these out. Instead I want to output the values of these fields as text and to be able to access their ActiveRecord relations.

How would I go about doing this?


To access object variables from a form helper do:

f.object.your_variable
0

精彩评论

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

关注公众号