8

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
Jeff Pole
  • 337
  • 2
  • 3
  • 12
  • 1
    possible duplicate of [add checkbox with simple\_form without association with model?](http://stackoverflow.com/questions/9182434/add-checkbox-with-simple-form-without-association-with-model) – Andy Hayden Sep 06 '13 at 09:54

1 Answers1

15

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} %>
Guilherme Franco
  • 1,465
  • 12
  • 19
Thiyagu
  • 169
  • 1
  • 5