acts_as_taggable_on and checkbox tags
Asked Answered
R

2

8

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'?

Rooney answered 14/7, 2011 at 17:37 Comment(0)
L
14

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 %>
Lumbar answered 9/10, 2011 at 8:48 Comment(0)
R
2

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.

Rockoon answered 22/9, 2016 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.