Ruby on rails 使用carmen gem获取州名称时面临的问题
嗨,我在我的应用程序中使用了Ruby on rails 使用carmen gem获取州名称时面临的问题,ruby-on-rails,ruby-on-rails-4,carmen,Ruby On Rails,Ruby On Rails 4,Carmen,嗨,我在我的应用程序中使用了gem'carmenrails',我有这种类型的关联 class Employee < ActiveRecord::Base has_one :contact has_one :permanent_address accepts_nested_attributes_for :contact, :permanent_address end 在我的路线中: resources :employees do collection do
gem'carmenrails'
,我有这种类型的关联
class Employee < ActiveRecord::Base
has_one :contact
has_one :permanent_address
accepts_nested_attributes_for :contact, :permanent_address
end
在我的路线中:
resources :employees do
collection do
get 'subregion_options'
end
end
在my employees/new.html.erb中
<%= form_for @employee do |f| %>
<label class="form_label">Email</label>
<%= f.text_field :email %>
<label class="form_label">Set Ex Employee</label>
<%= f.check_box :is_active %>
<%= f.fields_for :contact do |c| %>
<label class="form_label">Address 1</label>
<%= c.text_field :current_address1 %>
<%= c.country_select :country,:prompt => 'Select Country' %>
<%= render partial: 'subregion_select', locals: {parent_region: c.object.country} %>
<% end %>
<%= f.submit %>
<% end %>
但它不会吸引任何州。请指导如何解决这个问题。提前感谢。您得到的结果是什么?它显示在该条件下没有任何内容
elsif country.subregions代码>但无法显示相应的状态尝试子区域\u选择\u标记(名称、值、父区域\u或\u代码)
它实际上完成了它的fetchinbg,但它的css是display none,所以当我将其更改为display:block时;有效:)
<%= form_for @employee do |f| %>
<label class="form_label">Email</label>
<%= f.text_field :email %>
<label class="form_label">Set Ex Employee</label>
<%= f.check_box :is_active %>
<%= f.fields_for :contact do |c| %>
<label class="form_label">Address 1</label>
<%= c.text_field :current_address1 %>
<%= c.country_select :country,:prompt => 'Select Country' %>
<%= render partial: 'subregion_select', locals: {parent_region: c.object.country} %>
<% end %>
<%= f.submit %>
<% end %>
<div id="order_state_code_wrapper">
<% parent_region ||= params[:parent_region] %>
<% country = Carmen::Country.coded(parent_region) %>
<% if country.nil? %>
<em>Please select a country above</em>
<% elsif country.subregions? %>
<%= subregion_select(:contact, :state_code, parent_region) %>
<% else %>
<%= text_field(:contact, :state_code) %>
<% end %>
</div>
$('select#employee_contact_attributes_country').change(function() {
selectWrapper = $('#order_state_code_wrapper');
countryCode = $(this).val();
url = "/employees/subregion_options?parent_region=" + countryCode;
selectWrapper.load(url);
});