12

I have successfully set up acts_as_taggable_on my model. As expected, when I split the tags with commas, it splits the tags correctly.

However, when I edit the post the field is auto populated with the tags for editing, except the commas are now gone.

This means if I hit save without putting them back in, the tags now become all one tag.

I have tried using ActsAsTaggableOn.delimiter = ' ' which works when they are one word tags. But now I have the issue that if i have a two word tag, when I edit and save the post the two word tags now become one word tags.

Any help anybody might have on this would be greatly appreciated.

Thanks!

abbott567
  • 862
  • 6
  • 18
  • 2
    Try this in the form input: `<%= f.text_field :tag_list, value: @example_record.tag_list.join(",") %>` – Sony Mathew Feb 28 '15 at 01:38
  • Possible duplicate of [Rails 4: text\_field for acts\_as\_taggable\_on not separating tags with a comma](https://stackoverflow.com/questions/27646714/rails-4-text-field-for-acts-as-taggable-on-not-separating-tags-with-a-comma) – Jon Schneider Oct 04 '17 at 17:04

3 Answers3

22

This behavior is apparently by design in acts_as_taggable_on.

Try adding to_s to your tag_list in the form input:

<%= f.text_field :tag_list, value: @example_record.tag_list.to_s %>

Not ideal, but this should allow your field to display the comma separated tags properly.

Zoran
  • 4,196
  • 2
  • 22
  • 33
4

For simple_form use this:

<%= f.input :tag_list, input_html: {value: @example_record.tag_list.to_s} %>
bosp
  • 107
  • 10
0

If you are using just one word in your tags, you can use a space as a delimiter instead of commas.

config/initializers/acts_as_taggable_on.rb  

ActsAsTaggableOn.delimiter = ' ' # use space as delimiter

I think this is not ideal too, but solved the problem.