Jhonny Pamponet Jhonny Pamponet - 5 months ago 9
HTML Question

how to check check_box_tag is checked or not in rails

how to check check_box_tag is checked or not in rails?

I need to know what checkboxes is checked.

This system is to users generate reports baseds on options selects.

View:

<%= 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 %>


Controller:

def index
end

def finish
redirect_to root_path
end


Routes:

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

Answer

I use this code in 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>

And this in Controller:

@properties = params["name"]

And solved =D!!