I'm using RoR 3.0.8 and the gem acts_as_taggable_on. I want to make it so that a post can have any of the following tags (politics, sports, social, science). I want them to choose the tags when they create the post and do this using checkboxes. Is there a way to make it say that if the politics checkbox is check, then @post.tag_list='politics'?
A little delayed, but this should work.
<%= form_for(@post) do |f| %>
<%= f.label :tag_list %>
<%= f.check_box :tag_list, { :multiple => true }, 'politics', nil %>
<%= f.check_box :tag_list, { :multiple => true }, 'science', nil %>
<%= f.check_box :tag_list, { :multiple => true }, 'social', nil %>
<%= f.check_box :tag_list, { :multiple => true }, 'sports', nil %>
<% end %>
Late too, but: Checked out and tried to apply this answer myself, with rails 5, and the above code only worked when I put :tag_list => [] in post_params. For some reason just adding :tag_list doesn't work.
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