我想在Rails中使用form_for中的select方法。我不太清楚该怎么做。有人能指点我一个例子吗?
答案 0 :(得分:8)
您是在谈论select
还是select_tag
还是collection_select
?
# advanced users only
= f.select :field_id, options_for_select(Model.collect{|m| [m.name, m.id]})
# easiest, assuming you have a model
= f.collection_select :field_id, Model.all, :id, :name
# without model
= select_tag 'model[field_id]', @model.field_id, options_for_select(Model.collect{|m| [m.name, m.id]})