【发布时间】:2019-12-08 09:46:35
【问题描述】:
安装 country_state_select gem 后,它成功加载了国家,但我选择的第一个国家加载了相应的国家,但在选择另一个国家后,其相应的国家不会加载,而是属于我最后选择的国家的国家。我曾多次尝试关闭服务器以重置它,但仍然会这样做。
<%= simple_form_for(@office_item) do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if
f.object.errors[:base].present? %>
<div class="form-inputs">
<%= f.file_field :pictures, multiple:true %>
<%= f.input :title %>
<%= f.input :description %>
<%= f.association :category, label_method: :title, value_method: :id,
include_blank: false, prompt: "Select Category" %>
<%= f.input :address %>
<%= f.input :country, collection: CountryStateSelect.countries_collection
%>
<%= f.input :state, CountryStateSelect.state_options(label: "State /
Province", form: f, field_names: { :country => :country, :state =>
:state } ) %>
<%= f.input :city, CountryStateSelect.city_options(label: "City ",
form: f, field_names: { :state => :state, :city => :city } ) %>
<%= f.input :pricing, label: "Price" %>
<%= f.input :terms, label: "Terms and Conditions" %>
<%= f.input :is_active, label: "Publish" %>
</div>
<div class="form-actions">
<%= f.button :submit, class: "btn btn-secondary" %>
</div>
<% end %>
<script>
$(document).on('ready page:load', function() {
return CountryStateSelect({
country_id: "country",
state_id: "state"
city_id: "city"
});
});
</script>
我的期望是每个选择的国家都会分别加载其对应的州和城市
【问题讨论】:
-
控制台有错误吗?
-
感谢您的帮助。这是我在控制台上发现的错误:Uncaught SyntaxError: Unexpected identifier on city_id: "city" in the console。我在它之后添加了一个昏迷,错误消失了。但是,对所选国家/地区的相应州和城市的选择不起作用。
-
您在尝试选择其他国家/地区时是否遇到任何新错误?
标签: ruby-on-rails rubygems ruby-on-rails-5