I’m working on a test app where users can create ideas. I’m trying to give them the option of selecting if the idea will be recurring, using a checkbox (see below):
<div class= "field">
<%= check_box_tag(:recur) %>
<%= label_tag(:recur, "Recurring idea?") %>
</div>
Then, in my ideas index view, I want to display all the ideas with a column labeled “Recurring?” In that column I want to be able to show which ideas are recurring.
Currently, I set :recur as a :string, perhaps it should be something else?
In my ideas index view I have this code: <td><%= idea.recur? %></td> which just returns “false” in the “Recurring?” column for all ideas (checked and unchecked).
I know the line above is wrong and I’m not even sure if I setup the checkbox variable :recur correctly.
Please help! And I’d love some guidance as to the proper use of checkboxes inside views and how to manipulate the data that is chosen by the user.
Thanks!
I think you’ve got a disconnect between your form and your model.
The best way to implement this would be to create a boolean field called
recurringin yourideastable.Then, if you’re using
form_for(which you really should be), all you need to do is:You can read more about using
form_forhere: http://guides.rubyonrails.org/form_helpers.html#dealing-with-model-objects