这是我在ruby中的select标签,在提交表单后,我想编辑所选的选项。所以我在edit.htm.erb中完成了<%= render 'form' %>
,但是当我点击编辑按钮时,我提交的选项没有出现在选择字段中。它显示选择一个类别
请建议我解决此问题的解决方案 form.html.erb
<%= simple_form_for([:coaches, @programme]) do |f| %>
<%= f.input :title %>
<%= select_tag 'category', options_from_collection_for_select(@categories, 'id', 'name',@categories.category_id), :class => "wrapper-dropdown-3_1", :onchange => 'update_subscategories_div(this.value)', prompt: "Select a Category" %>
<%= f.button :submit, "PUBLISH", :class => "btn_style" %>
edit.html.erb
<%= render 'form' %>
答案 0 :(得分:1)
您需要在options_from_collection_for_select方法中将所选元素的id作为第三个参数传递。
<%= select_tag 'category', options_from_collection_for_select(@categories, 'id', 'name',category_id), :onchange => 'update_subscategories_div(this.value)', prompt: "Select a Category" %>
答案 1 :(得分:1)
setTextZoom()