ruby on rails - How to show if something is checked in a view using checkboxes? -
i'm working on test app users can create ideas. i'm trying give them option of selecting if idea recurring, using checkbox (see below):
<div class= "field"> <%= check_box_tag(:recur) %> <%= label_tag(:recur, "recurring idea?") %> </div>
then, in ideas index view, want display ideas column labeled "recurring?" in column want able show ideas recurring.
currently, set :recur
:string
, perhaps should else?
in ideas index view have code: <td><%= idea.recur? %></td>
returns "false" in "recurring?" column ideas (checked , unchecked).
i know line above wrong , i'm not sure if setup checkbox variable :recur
correctly.
please help! , i'd love guidance proper use of checkboxes inside views , how manipulate data chosen user.
thanks!
i think you've got disconnect between form , model.
the best way implement create boolean field called recurring
in ideas
table.
then, if you're using form_for
(which should be), need is:
<%= form_for @idea |f| %> <%= f.check_box :recurring %> <%= f.label :recurring %> <% end %>
you can read more using form_for
here: http://guides.rubyonrails.org/form_helpers.html#dealing-with-model-objects
Comments
Post a Comment