【发布时间】:2011-10-05 19:24:04
【问题描述】:
我有一个带有 3 个下拉菜单的视图。 For example i have Country, State and City and in the view when the user select Country = US, then in the State dropdown it should populate a list of only US states, and when the state is selected the dropdown only need to bring up the该州属下的城市。我的数据库设置正确(State 有 state name 和 country_id 字段,City 有城市名称和 state_id)
我在视图中实现了以下内容,但这会给我带来所有记录,无论用户选择如何。
<div class="field">
<%= f.label :sector, "Sector" %>
<%= f.collection_select :sector_id, Sector.all, :id, :nombre, :prompt => false %>
</div>
<div class="field">
<%= f.label :municipio %>
<%= f.collection_select :municipio_id, Municipio.all, :id, :nombre, :prompt => false %>
</div>
<div class="field">
<%= f.label :provincia %>
<%= f.collection_select :provincia_id, Provincia.all, :id, :nombre, :prompt => false %>
</div>
如何使这些下拉列表相互依赖?
【问题讨论】:
标签: jquery ajax ruby-on-rails-3