# Acts\_as\_taggable / Rails Recipes bug?

**URL:** <https://www.ruby-forum.com/t/acts-as-taggable-rails-recipes-bug/101770>\
**Category:** Rails\
**Created:** [August 7, 2006, 9:19pm UTC](https://www.ruby-forum.com/t/acts-as-taggable-rails-recipes-bug/101770 "2006-08-07T21:19:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_PSVerni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/46a35a/32.png) [@Nathan\_PSVerni](https://www.ruby-forum.com/u/Nathan_PSVerni)\
**Post date:** [August 7, 2006, 9:19pm UTC](https://www.ruby-forum.com/t/acts-as-taggable-rails-recipes-bug/101770/1 "2006-08-07T21:19:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nathan\_PSVerni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/46a35a/32.png) [@Nathan\_PSVerni](https://www.ruby-forum.com/u/Nathan_PSVerni)\
**Post date:** [November 26, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/acts-as-taggable-rails-recipes-bug/101770/2 "2006-11-26T17:54:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nathan\_PSVerni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/46a35a/32.png) [@Nathan\_PSVerni](https://www.ruby-forum.com/u/Nathan_PSVerni)\
**Post date:** [November 26, 2006, 7:20pm UTC](https://www.ruby-forum.com/t/acts-as-taggable-rails-recipes-bug/101770/3 "2006-11-26T19:20:28Z")

</div>

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

🙂

---

<div class="post-metadata">

**Author:** ![Nathan\_PSVerni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/46a35a/32.png) [@Nathan\_PSVerni](https://www.ruby-forum.com/u/Nathan_PSVerni)\
**Post date:** [November 26, 2006, 7:53pm UTC](https://www.ruby-forum.com/t/acts-as-taggable-rails-recipes-bug/101770/4 "2006-11-26T19:53:52Z")

</div>

just a custom, add a if test to after\_save callback

def after\_save  
self.tag\_with @tag\_list if @tag\_list  
end
