I want to get the value "0" (not checked) or "1" (checked) from check_box and save it as hash value. But no value can be saved... paper: nil I created the column "paper" as integer. Can someone help me?
Here is my code:
View:
<div class="formgroup">
<%= f.label :paper, "Paper_Collection" %>
<% @paper.each do |key, value| %>
<div class="checkbox" >
<%= f.check_box :paper, {checked: false, multiple: true}, value == "1" ? "checked" : "" %><%= key %>
</div>
<% end %>
</div>
Controller:
def new
@box = Box.new
@paper = {red: 0, blue: 0, yellow: 0, green: 0, black: 0, white: 0}
....
end
def create
@box = Box.new(box_params)
@box.user_id = current_user.id
@paper = {red: 0, blue: 0, yellow: 0, green: 0, black: 0, white: 0}
...
end
private
def box_params
params.require(:box).permit(:status, :paper, :cable, reports: [])
end
Aucun commentaire:
Enregistrer un commentaire