2012-12-25 31 views
0

当我加载用户的编辑页面时,它显示此错误。为什么?为什么使用'grouped_collection_select'时我没有方法错误?

在我的模型有模型,如

  • 用户(这种模式有一个用户配置)
  • 用户配置(此模型属于用户,并有一个国家和一个地区)
  • 国家(这种模式属于USERPROFILE,并且有许多省)
  • 县(此模型属于国家和用户配置)

错误

未定义的方法'名称”的#

_form.html.erb

<%= f.fields_for :user_profile do |profile_form| %> 
    <%= profile_form.label :country_id %><br /> 
    <%= profile_form.collection_select :country_id, Country.order(:name_en), :id, :name_en, include_blank: true %> 

    <%= profile_form.label :prefecture_id, "State or Province" %><br /> 
    <%= profile_form.grouped_collection_select :prefecture_id, Country.order(:name_en), :prefectures, :name, :id, :name, include_blank: true %> 
<% end %> 

型号/ country.rb

的has_many:都道府县

型号/ prefectures.rb

belongs_to的:国家

回答

1

试试这个,

<%= profile_form.grouped_collection_select :prefecture_id,Country.order(:name_en),:prefectures, :name_en, :id, :name,include_blank: true %> 
+0

非常感谢你 – HUSTEN

相关问题