如何显示房间类别的名称,然后存储它的ID而不是名称 我尝试过使用以下声明
= f.select :room_category_id, RoomCategory.all.pluck('name'), {}, class: "form-control"
然后我也将其替换为以下语句,名称显示但我无法改写值
= f.select :room_category_id, RoomCategory.all.pluck('name'), {}, class: "form-control"
答案 0 :(得分:0)
试试这个:
= f.select :room_category_id, RoomCategory.all.map { |c| [c.name, c.id]}
答案 1 :(得分:0)
试试这个
= f.select :room_category_id, RoomCategory.collect{|p| [p.name, p.id]}, {},class: "form-control"
希望,这会对你有帮助。