I'm trying to add a checkbox input to my simple form in Rails. I only need the input for javascript and don't actually want it in my model file.
I've learned that in order to add inputs to simple form that do not exist in the model a value has to be passed in the parameters
input_html: {value: true}
This works for a text input, but I can't get it working for a checkbox.
I've tried
<%= f.input :current_job, :as => :check_box, input_html: {value: false} %>
and
<%= f.input :current_job, :as => :check_box, input_html: {checked: false} %>
But I get an error saying
No input found for check_box
You should use type as boolean in your fields. In your case, you can change this:
<%= f.input :current_job, :as => :check_box, input_html: {checked: false} %>
to this:
<%= f.input :current_job, :as => :boolean, input_html: {checked: false} %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With