开发者

acts_as_taggable_on and checkbox tags

开发者 https://www.devze.com 2023-03-20 14:45 出处:网络
I\'m using RoR 3.0.8 and the gem act开发者_StackOverflows_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

I'm using RoR 3.0.8 and the gem act开发者_StackOverflows_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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号