0

当转到表单的编辑视图时,将值先前发布到数据库中,除下拉菜单字段外,所有字段都将重新填充。例如,“惊讶”值现在在数据库中。当我打开编辑页面时,我只看到默认的“选择选项...”

这是我的表格中的内容:

<%= f.select :emotion, options_for_select([["Happy", "Happy"], ["Afraid", "Afraid"], ["Sad", "Sad"], ["Surprised", "Surprised"], ["Inspired", "Inspired"]]), :include_blank => 'Select Option...' %>

如何让它重新填充?

4

2 回答 2

0

利用:

options_for_select([["Happy", "Happy"], ["Afraid", "Afraid"], ["Sad", "Sad"], ["Surprised", "Surprised"], ["Inspired", "Inspired"]], <selected_value>)
于 2013-08-11T08:47:12.440 回答
0

刚刚想通了!将 :include_blank 的值更改为数据库中的实际变量。

<%= f.select :emotion, ([["Happy", "Happy"], ["Afraid", "Afraid"], ["Sad", "Sad"], ["Surprised", "Surprised"], ["Inspired", "Inspired"]]), :include_blank => @table_name.emotion %>
于 2013-08-11T18:16:17.027 回答