I have an Entry model which has_many :tags. I want to be able to list my tags in an text input (ie. "tag-1, tag-2", etc.), however, I am running into an issue.
If I just use
form_for(:entry, form_options) do |f|
f.text_field :tags
end
My text box gets created, but is filled with something like #<Tag:0xb79fb584>#<Tag:0xb79faddc>, which is obviously not what I'm looking for.
I know I can add a to_s method to Tag:
class Tag < ActiveRecord::Base
def to_s
name # the name of the tag
end
end
But that just leaves me with something like tag-1tag-2 because @entry.tags.to_s still just refers to Array#to_s.
Right now, I am using
f.text_field :tags, :value => @entry.tags.map(&:name).join(", ")
instead, which will display the correct string, but doesn't feel like the "rails way" of doing things. Is there a way I can add a custom to_s method specifically to my tags association?