1

こんにちは、私は国と州のリストに carmen gem を使用しています。

私のビューコードは、

<div class=" control-group">
  <%= f.label :country, :class => 'control-label' %>
  <div class="controls">
    <%= f.select :country, Carmen::Country.all.collect{|c| c.name}, {:selected => country}, :remote=>true %>
  </div>
</div>
<div class=" control-group">
  <%= f.label :state, :class => 'control-label' %>
  <div id="addressStates">
    <%= render :partial => 'experienceones/states', :locals => {:states => Carmen::Country.named('India').subregions.collect{|sub| sub.name }, :form => f} %>
    </div>
  </div>

部分的な状態は、

<div class="controls">
  <%= fields_for 'experienceones' do |addr_form| %>
    <% if !@states.blank? %>
  <%= addr_form.select :state, @states, {:prompt => 'Select State'}, {:style => 'width: 180px'} %>
<% else %>
  <%= addr_form.text_field :state %>
<% end %>
  <% end %>
</div>

jqueryは、

jQuery('select#experienceone_country').change(function() {
  var country = 'country=' + $('select#experienceone_country :selected').text();
  jQuery.ajax({
    url: '/experienceones/update_state_select',
    data: country,  
    dataType: 'html',
    success: function(data){
      jQuery("div#addressStates").html(data);

      },
  });
});

そして私が持っているコントローラーで、

def update_state_select
  @states = Carmen::Country.named(params[:country]).subregions.collect{|sub| sub.name } || []
end

国を選択すると、選択タグで州のリストを正常に取得できます。

しかし、私はエラーが発生します、

No route matches [GET] "/experienceones/1/true"

私は知っています、本当は私の要求の結果です

GET "/experienceones/update_state_select?country=######"

どうすればこれを回避できますか?

編集用の私のURLは

http://localhost:3000/experienceones/1/edit

私が使用する場合、

window.location.href = "/experienceones/<%= @experience.id %>/edit"

ajaxの成功で、新しい編集ページを取得しました。

選択した国と州と同じページ (つまり編集ページ) にリダイレクトしたい。

これどうやってするの?

同じ問題は新しいものです。

ありがとうございました。

4

0 に答える 0