Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding checkbox to simple form for input not in model

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
like image 877
Jeff Pole Avatar asked Feb 27 '13 15:02

Jeff Pole


1 Answers

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} %>
like image 79
Thiyagu Avatar answered Sep 30 '22 02:09

Thiyagu