标签: ruby-on-rails
答案 0 :(得分:5)
当您希望select元素中的选项来自ActiveRecord模型集合时,使用collection_select帮助程序。根据您的要求,您应该将select助手与options_for_select结合使用:
collection_select
select
options_for_select
<%= select(:country, :country_id, options_for_select([['US', 1], ['UK', 2], ['AUS', 3], ['PAK', 4]])) %>