如何检查check_box_tag是否已在rails中检查?
我需要知道检查了哪些复选框。
该系统是用户根据选项选择生成报告。
查看:
<%= form_tag finish_reports_path do %>
<div class="row top30 reload">
<div class="col-sm-12 col-xs-12">
<div class="form-inline">
<%= check_box_tag("name", "1", false, class: "checkbox") %>
<%= label_tag :name, "Nome do Conteúdo" %>
</div>
<div class="form-inline">
<%= check_box_tag(:url, "2", false, class: "checkbox") %>
<%= label_tag :url, "URL do Conteúdo" %>
</div>
<%= link_to t("button.generate"), finish_reports_path(finish: "yes"), :class => "btn btn-success" %>
</div>
</div>
<% end %>
控制器:
def index
end
def finish
redirect_to root_path
end
路线:
root "reports#index"
post "/" => "reports#read_combo", as: :read_reports_combo
get "/reports/generate/:type" => "generate#index", as: :reports_generate
get "/reports/generate" => "generate#finish", as: :finish_reports
答案 0 :(得分:1)
如果未选中该复选框,则不传递参数,这意味着该值为false。如果选中该复选框,则参数将显示在控制器中。如果要将伪值传递给参数,请创建隐藏字段,并将hidden_input
值设置为false
。
我相信这是重复的。 Rails checkbox and params
答案 1 :(得分:0)
我在View中使用此代码:
<div class="form-inline">
<%= check_box_tag("name[]", "i18n.name", false, class: "checkbox") %>
<%= label_tag :name, "Nome do Conteúdo" %>
</div>
<div class="form-inline">
<%= check_box_tag("name[]", "url.url", false, class: "checkbox") %>
<%= label_tag :url, "URL do Conteúdo" %>
</div>
这在Controller中:
@properties = params["name"]
并解决了= D !!