Andrey Drozdov Andrey Drozdov - 3 months ago 10
reST (reStructuredText) Question

Ruby on Rails checkbox doesn't change value

I'm using 'form for' to send form information and I have a few categories (in my db, they are boolean). To confirm information about categories I use checkbox. But it is not working and I can't understand why.

<%= form.label :lifehacks, "Lifehacks" %>
<%= form.check_box :lifehacks, :class => 'checkbox-in-create-post' %>


And when I go to console and view created post - category "Lifehacks" is false (what is default value). And it's not changing even if checkbox is checked.

But interesting fact: the same code for other category:

<%= form.label :photos, "Photos" %>
<%= form.check_box :photos, :class => 'checkbox-in-create-post' %>


if checkbox is checked is changing category "Photos" boolean to true.

If you need some addition information - tell me.

Can you tell me where I've made my mistake?

Answer

You forgot to permit the lifehacks parameter in the controller so is not updated. Look for params.require(something).permit(:photos, etc...) and add your missing lifehacks parameter in the list of permitted attributes.