如何在选择下拉列表中显示所选值

时间:2014-03-16 08:59:21

标签: ruby-on-rails ruby

我有一个键值对数组:

FEEDBACK_NOTIFICATION = [['Only in reports', 'only_in_reports'],['Immediately', 'immediately']] 

在我看来,我尝试过:

<%= f.select(:feedback_schedule, FEEDBACK_NOTIFICATION, options ={:prompt => "-Select-"}) %>

<%= f.select(:feedback_schedule, options_for_select(FEEDBACK_NOTIFICATION), options ={:prompt => "-Select-"}) %>

<%= f.select(:feedback_schedule, options_for_select(FEEDBACK_NOTIFICATION, selected: feedback_schedule), options ={:prompt => "-Select-"}) %>

即使数据库已更新,当我返回编辑页面时,这些似乎都不会显示所选/更新的值。

1 个答案:

答案 0 :(得分:2)

&lt;%= f.select(:feedback_schedule,options_for_select(FEEDBACK_NOTIFICATION,selected:@ object.feedback_schedule),options = {:prompt =&gt;&#34; -Select - &#34;})%&gt;会工作