I'm switching off of acts_as_taggable_on because of limited flexibility for my current application. Instead, I'm building my tags from scratch as their own model. However, I already miss the "@model.tag_list" method for forms, that would split up comma-delimited user input and make individual tags. My "taggable" model is a video, and I'm curious how to write a method that can essentially act like the "tag_list"?
Example:
<%= form_for @video do %>
<%= f.text_field :tag_list %>
....
Given the input: "one, two, three"
Would build three Tags as children of the @video.
@video.tags.each do |tag|
puts tag.name
end
=> one
two
three
EDIT
I'd really like this in the Tag model, to keep form cluttering my controller. Maybe as a custom attribute? Maybe the Video model would make more sense? I know how to make a custom method to return custom data, but not assign it. Some research points me this way (not yet tested)
video.rb
def tag_list=value
value.split(',').each do |tag|
self.tags.build(:name => tag).save
end
end
You can leave tag_list as an attribute on Video, then in your create you could just have something like:
It seems like my example code ended up working
video.rb
EDIT
Also need to add to get it to work in a form: