0

嗨我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

在我的员工/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);
  });

但它没有获取任何状态。请指导如何解决这个问题。提前致谢。

4

0 回答 0