如何在 gem 'carmen-rails', '~> 1.0.0' 中给出国家简称和州简称
how to give country short and state short names in gem 'carmen-rails', '~> 1.0.0'
我的观点是:
<div class="input-control select country_input" data-role="input-control">
<%= f.select :country, region_options_for_select(only_us_and_france),:prompt => 'Select Country' %>
</div>
<div class="input-control select state_input" data-role="input-control">
<%= render partial: 'subregion_select', locals: {parent_region: f.object.country} %>
</div>
在我的次区域部分:
<div id="account_state_code_wrapper" >
<% parent_region ||= params[:parent_region] %>
<% country = Carmen::Country.coded(parent_region) %>
<% if country.nil? %>
<div style="display: none">State</div>
<% elsif country.subregions? %>
<%= subregion_select(:account_detail, :state_code, parent_region) %>
<% else %>
<%= text_field(:account_detail, :state_code) %>
<% end %>
</div>
在我的助手中它是:
def only_us_and_france
Carmen::Country.all.select{|c| %w{US FR}.include?(c.code)}
end
所以它显示了国家和州的名称,但我想在我的 select 选项中显示美国和法国等州的名称。
请帮帮我。提前致谢。
试试这个。
添加名为 region_options_us_and_france
的新辅助方法:
def region_options_us_and_france
Carmen::Country.all.select{|c| %w{US FR}.include?(c.code)}.map { |r| [r.code, r.code] }
end
def sub_region_options(region)
region.subregions.map { |r| [r.code, r.code] }
end
并更新视图:
<div class="input-control select country_input" data-role="input-control">
<%= f.select :country, region_options_us_and_france, :prompt => 'Select Country' %>
</div>
变化 'subregion partial'
<%= subregion_select(:account_detail, :state_code, parent_region) %>
和
<%= f.select :your_field_attr, sub_region_options(country), :prompt => 'Select Sub region' %>
我的观点是:
<div class="input-control select country_input" data-role="input-control">
<%= f.select :country, region_options_for_select(only_us_and_france),:prompt => 'Select Country' %>
</div>
<div class="input-control select state_input" data-role="input-control">
<%= render partial: 'subregion_select', locals: {parent_region: f.object.country} %>
</div>
在我的次区域部分:
<div id="account_state_code_wrapper" >
<% parent_region ||= params[:parent_region] %>
<% country = Carmen::Country.coded(parent_region) %>
<% if country.nil? %>
<div style="display: none">State</div>
<% elsif country.subregions? %>
<%= subregion_select(:account_detail, :state_code, parent_region) %>
<% else %>
<%= text_field(:account_detail, :state_code) %>
<% end %>
</div>
在我的助手中它是:
def only_us_and_france
Carmen::Country.all.select{|c| %w{US FR}.include?(c.code)}
end
所以它显示了国家和州的名称,但我想在我的 select 选项中显示美国和法国等州的名称。 请帮帮我。提前致谢。
试试这个。
添加名为 region_options_us_and_france
的新辅助方法:
def region_options_us_and_france
Carmen::Country.all.select{|c| %w{US FR}.include?(c.code)}.map { |r| [r.code, r.code] }
end
def sub_region_options(region)
region.subregions.map { |r| [r.code, r.code] }
end
并更新视图:
<div class="input-control select country_input" data-role="input-control">
<%= f.select :country, region_options_us_and_france, :prompt => 'Select Country' %>
</div>
变化 'subregion partial'
<%= subregion_select(:account_detail, :state_code, parent_region) %>
和
<%= f.select :your_field_attr, sub_region_options(country), :prompt => 'Select Sub region' %>