Ruby on rails Rails 4字段\u用于更新-默认选择不起作用

Ruby on rails Rails 4字段\u用于更新-默认选择不起作用,ruby-on-rails,ruby,ruby-on-rails-4,form-for,fields-for,Ruby On Rails,Ruby,Ruby On Rails 4,Form For,Fields For,我现在正在从事Rails 4项目,我在字段_中选择以更新表单 <%= f.fields_for :ingredients do |ingredient_fields|%> <%= ingredient_fields.text_area :name %> <%= ingredient_fields.select :price do %> <%= options_for_select([['cheap', 1], ['expensive', 2]]

我现在正在从事Rails 4项目,我在
字段_中选择
以更新
表单

<%= f.fields_for :ingredients do |ingredient_fields|%>
 <%= ingredient_fields.text_area :name %>
 <%= ingredient_fields.select :price do %>
   <%= options_for_select([['cheap', 1], ['expensive', 2]], :price) %>
 <% end %>
 <%= link_to_remove_fields 'Remove this ingredient', f %>
<% end %>

但是,此更新表单不反映
:price
属性,而
component
对象已经具有该属性

(例如,即使我有一个具有
昂贵
:price
属性的配料对象,默认情况下该对象的选择输入也不会选择
昂贵
。)


更新时,如何设置
字段中
选择
的默认值?

成分字段中的
是否默认值。选择:价格,[[['便宜',1],'昂贵',2]
在没有块的情况下工作?或者
options\u为您的对象选择([[['cheap',1],'price',2]],此处为price)
应该这样做。现在您只是将一个符号
:price
作为所选值传递,而该值在“容器”中不存在。是的,第一个建议对我有效!谢谢!:)(我无法尝试第二个,因为我没有可以访问的特定成分对象,因为我正在使用字段_。)