Reputation: 6496
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'?
Upvotes: 8
Views: 1482
Reputation: 117
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.
Upvotes: 2
Reputation: 14205
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 %>
Upvotes: 14