在rails 项目中
有2个表
create_table "cities", force: :cascade do |t|
t.string "name"
t.integer "province_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["province_id"], name: "index_cities_on_province_id"
end
create_table "provinces", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
在cities/index.html中想实现
前一个选择框可以选择某个省,第二个选择框自动提供所选省份的地级市(县)
<%=
collection_select(:city, :province_id, Province.all, :id, :name_with_initial, { prompt: true })
%>
<%=select_tag "city", option_groups_from_collection_for_select(@province, :cities, :name, :id, :name, 30)%>
要怎么做