2012-12-25 40 views
0

我想顯示國家分隔選擇字段。
但是縣一起在表上表示國名以及全部的縣。是否可以只顯示屬於所選國家的縣?

我怎樣才能將縣的記錄限制在屬於國家的唯一縣,這在以前的選區中是被選中的?

在我的模型有模型,如

  • 用戶(這種模式有一個用戶配置)
  • 用戶配置(此模型屬於用戶,並有一個國家和一個地區)
  • 國家(這種模式屬於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_en, :id, :name,include_blank: true %> 

<% end %> 

型號/ country.rb

的has_many:都道府縣

型號/ prefectures.rb

belongs_to的:國家

+0

您可以使用國家查看縣 –

回答

0

你要開槍國家的變化,這將根據國家獲取縣名單Ajax請求

你可以參考blog post這將幫助你如何實現this.you能也參考源代碼。

相關問題