Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

acts_as_taggable_on and checkbox tags

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

like image 213
Vasseurth Avatar asked Jul 14 '11 17:07

Vasseurth


2 Answers

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 %>
like image 65
Adam Eberlin Avatar answered Oct 13 '22 18:10

Adam Eberlin


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.

like image 21
sneglefar Avatar answered Oct 13 '22 19:10

sneglefar