据我了解,您正在为一个select
没有country_select
功能的领域寻找加拿大各省和美国各州的联合。如果我是对的,你可以通过这种方式
countries = Carmen::Country.all.select{|c| %w{US CA}.include?(c.code)} # get the countries
# get the subregions of US and CA
subregions = countries.collect {|x| x.subregions }.flatten
在轨道应用中
创建辅助方法
def subregions_of_us_and_canada
countries = Carmen::Country.all.select{|c| %w{US CA}.include?(c.code)}
# get subregions and sort in alphabetical order
countries.collect {|x| x.subregions }.flatten.sort_by(&:name)
end
在表单中调用上述方法
= extra_fields.input :province, as: :select, collection: subregions_of_us_and_canada, label_method: :name, value_method: :code, label: "Franchisee Billing State/Province", input_html: { class: "form-control" }, prompt: 'Please select a state'
我希望这会有所帮助