Acts_as_taggable / Rails Recipes bug?

I’m following the acts_as_taggable chapter from the Rails Recipes book.
I want my view form to have a text_field that correlates to an attribute
in the Model that accepts a string of space delimited tags. The book
uses tag-_list, but from what I can tell this attribute can’t be written
to. I’ve added this to the plugin code itself - am I missing something,
is there a better way?

def tag_list=(s)

self.tag_with(s)

end

I think i have the same problem? you try to tag your model in a new form
? (when you create it ) no?

It’s work for me in a form_tag when i use <%= text_field ‘tags’, ‘’
%>
and use tag_with method in controller,
but now i’am trying with form_for and it’s doesn’t work because
text_field depend on the form object which don’t accept other text_field
that the model permit (one by attribute, no more)…

did you find a solution ?

Nathan P. Verni wrote:

I’m following the acts_as_taggable chapter from the Rails Recipes book.
I want my view form to have a text_field that correlates to an attribute
in the Model that accepts a string of space delimited tags. The book
uses tag-_list, but from what I can tell this attribute can’t be written
to. I’ve added this to the plugin code itself - am I missing something,
is there a better way?

def tag_list=(s)

self.tag_with(s)

end

I first tried to deal with a new method in my model :

def tags=(tags)
self.tag_with(tags)
end

it worked in prefectly in script/console but not in my app, i don’t know
why?
So i searched in googlecode and found another solution, pretty easy in
fact…

in your model adds:

attr_writer :tag_list

def after_save
self.tag_with @tag_list
end

in your new form_for :
<%= f.text_field :tag_list %>

And of course in the controller :

@model = Model.new(params[:model])
@model.save

:slight_smile:

just a custom, add a if test to after_save callback

def after_save
self.tag_with @tag_list if @tag_list
end