Forum: Ruby on Rails acts_as_taggable => error: undefined method 'tag'

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Judd S. (Guest)
on 2006-01-31 00:16
I get an "undefined method 'tag'" when I try to use the
acts_as_taggable.

Note that it's not the issue of bouncing webrick after changing the
environment.rb file. (I stumbled on that too... :-( ).

I read all the doc I could find (on this site, on
http://rails.techno-weenie.net and at http://taggable.rubyforge.org/)
but I couldn't find anything I might be doing wrong.

I marked my Item model as "acts_as_taggable" right at the top and in
item_controller::create method I'm calling @item.tag method after saving
the item.

#item.rb
class Item < ActiveRecord::Base
acts_as_taggable
...

#item_controller.rb
...
if @item.save
  @item.reload
  @item.tag("cool")
  redirect_to :action => 'show', :id=> @item.id
end
...

Any help will be greatly appreciated!
Thanks in advance...
Judd S. (Guest)
on 2006-01-31 01:22
The resolution is very interesting but it has nothing to do with
acts_as_taggable.

At some point I realized that no changes in the model (item.rb) are
picked up by rails. No matter what I tried (I even reboot my machine),
rails kept happy with a model file that, at that point, had obvious junk
in it.

Turns out rails was picking up an older file from a subdirectory of the
models directory (i.e. app/models/save/item.rb). I had to change that
file name to xitem.rb to convince rails it is not my model file.

Looks like a bug in rails to meâ?¦

Considering this is the first time I loose a few hours to a stupid rails
bug after a few months of using it, I guess I canâ??t complain. But still,
it was pretty frustrating :-(

Judd Ster wrote:
> I get an "undefined method 'tag'" when I try to use the
> acts_as_taggable.
>
> Note that it's not the issue of bouncing webrick after changing the
> environment.rb file. (I stumbled on that too... :-( ).
>
> I read all the doc I could find (on this site, on
> http://rails.techno-weenie.net and at http://taggable.rubyforge.org/)
> but I couldn't find anything I might be doing wrong.
>
> I marked my Item model as "acts_as_taggable" right at the top and in
> item_controller::create method I'm calling @item.tag method after saving
> the item.
>
> #item.rb
> class Item < ActiveRecord::Base
> acts_as_taggable
> ...
>
> #item_controller.rb
> ...
> if @item.save
>   @item.reload
>   @item.tag("cool")
>   redirect_to :action => 'show', :id=> @item.id
> end
> ...
>
> Any help will be greatly appreciated!
> Thanks in advance...
This topic is locked and can not be replied to.