rails 使用 coffee 实现本页动态填写数据

在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)%>

要怎么做

阅读 1.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏