0

我无法使用 select_tag 获取选定的值。在我的 new.html.erb 上,我有以下代码:

<%= select_tag "dams_provenance_collection[subjectType][]",  options_for_select(subjectTypeArray), :prompt=>"Select subject type" %>

在edit.html.erb上,我想使用从new.html.erb中选择的值作为默认值,所以我尝试了:

<%= select_tag 'dams_provenance_collection[subjectType][]',  options_for_select(subjectTypeArray, params[:selected])  %>

但它没有用。有谁知道如何将 new.html.erb 中的选定值设置为 edit.html.erb 中的默认值?任何帮助,将不胜感激。

4

2 回答 2

3

尝试这个,

<%= select_tag "dams_provenance_collection[subjectType][]", options_for_select(array_values, :selected => params[:option]) %>
于 2013-07-12T05:57:36.913 回答
1

试试这样:

= select_tag :chart_time_id, options_for_select(@times_collect, :selected => params[:num_days].present? ? params[:num_days].to_i : 7), {class: 'form-control selectpicker', 'data-style'=> "btn-info", required: true}

只需检查参数是否存在,并使用内联运算符(如果 -else)

于 2017-04-06T14:59:00.873 回答