您好我在我的应用中使用gem 'carmen-rails'
我有这种类型的关联
class Employee < ActiveRecord::Base
has_one :contact
has_one :permanent_address
accepts_nested_attributes_for :contact, :permanent_address
end
在我的employess_controller.rb中我定义如下:
def subregion_options
render partial: 'subregion_select'
end
在我的路线中:
resources :employees do
collection do
get 'subregion_options'
end
end
在我的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 %>
员工中的/ _subregion_select.html.erb
<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>
在js文件中
$('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);
});
但它没有取得任何国家。请指导如何解决这个问题。提前谢谢。