我终于弄清楚了如何使用本教程实现动态选择菜单。
一切正常,但是如何按名称组织下拉列表中的城市....
以下是我编写的所有代码。(如果您需要任何进一步的信息,请告诉我)
Rails 新手请帮忙:)
意见
<%= simple_form_for ([@book, @rating]) do |f| %>
<div class="field">
<%= f.collection_select :state_id, State.order(:name), :id, :name, {:include_blank=> "Select a State"}, {:class=>'dropdown'} %>
</div>
### I would like the order of the cities displayed in the drop down to be alphabetized
<div class="field">
<%= f.grouped_collection_select :city_id, State.order(:name), :cities, :name, :id, :name, {:include_blank=> "Select a City"}, {:class=>'dropdown'} %>
</div>
<% end %>