Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - acts_as_taggable_on Removes Commas When Editing

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!

like image 436
abbott567 Avatar asked Feb 28 '15 00:02

abbott567


1 Answers

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.

like image 121
Zoran Avatar answered Sep 20 '22 07:09

Zoran