0
我有一个名为Car
的模型的Rails表单,其中:location
属性的分组选择字段使用grouped_options_for_select
表单助手创建。我遇到的问题是,如果要编辑我已保存到数据库的Car
,则存储在:location
属性 - :location_id
中的值不会显示在选择字段中作为选定值。相反,选择字段显示为空白,未选择任何值。我有其他选择字段的表单上没有分组,并没有这个问题。我的表单辅助看起来像Rails分组选择字段不显示选定的值
<%= car_info_field.select :location_id, grouped_options_for_select(@grouped_locations),
{ include_blank: true }, { class: "form-control" } %>
我的模型看起来像
class Car < ActiveRecord::Base
belongs_to :location
validates :location_id, presence: true
我怎样才能获得分组选择字段显示编辑表单上选择权值?
我想你需要为你的location_id添加attr_accessible – trueinViso