我的第一列中有一个带复选框的表,另一列中有一个计划名列表。我希望能够选中列表旁边的框,单击form_submit按钮,并将这些选中的列表另存为数据库中的列。
我使用数组列运行表 - 我可以手动将数组输入到列中(使用名为Adminium的数据库管理服务)。但是,只要我尝试通过应用程序更新数组值,它就会清除数组值并且不会添加所选项目。
查看
<%= form_tag :action => 'planselection', :id => @current_plan.id, :method => :put do %>
<%= submit_tag "Add Selected Plans to Quote" %>
<table id="DT" class="table table-striped table-hover">
<thead>
<tr>
<th></th>
<th>Plan name</th>
<th>Carrier</th>
<th>Plan type</th>
<th>Deductible</th>
<th>Monthly Premium</th>
<th></th>
</tr>
</thead>
<tbody>
<% @benefit_details.where(:plan_year => @current_plan.plan_year).each do |benefit_detail| %>
<tr>
<td><%= check_box_tag "plan_selection[]", benefit_detail.plan_name %></td>
<td><%= benefit_detail.plan_name %></td>
<td><%= benefit_detail.carrier %></td>
<td><%= benefit_detail.plan_type %></td>
<td><%= benefit_detail.deductible %></td>
<td><% @AgeTest = AgeFactor.where("carrier = ? AND age = ?", @Carrier, @Age).pluck(:age_factor) %></td>
<td>
<a href="#" class="btn btn-circle btn-default btn-xs ">
<i class="fa fa-search"></i></a>
<a href="#" class="btn btn-circle btn-default btn-xs ">
<i class="fa fa-bar-chart-o"></i></a>
<a href="#" class="btn btn-circle btn-default btn-xs ">
<i class="icon-plus"></i></a>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
控制器
def planselection
# TODO Add all plan selections to Current plan
@current_plan.update(plan_selection: "plan_selection")
#@current_plan.update("plan_selection=?", :planselection)
redirect_to :back
end
终端输出
Started POST "/current_plans/planselection?id=12&method=put" for 66.186.164.130 at 2015-07-01 17:46:32 +0000
Processing by CurrentPlansController#planselection as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"aEwaOrQwzbSKkeLbdyJ3=", "commit"=>"Add Selected Plans to Quote", "DT_length"=>"10", "plan_selection"=>["Silver HMO 2,000 - MD3487/RX1028", "Silver HMO 2,000 - MD3487/RX1022", "Silver HMO 2,500 - MD3486/RX1021", "Silver HMO 2,500 - MD3486/RX1022"], "id"=>"12", "method"=>"put"}
CurrentPlan Load (30.5ms) SELECT "current_plans".* FROM "current_plans" WHERE "current_plans"."id" = $1 LIMIT 1 [["id", 12]]
(30.5ms) BEGIN
(30.3ms) COMMIT
答案 0 :(得分:0)
试试这个 - &gt; @ current_plan.update(plan_selection:params [:plan_selection])