Question

Edit

The instructions on Github instruct you to use the gemcutter source for the gem. Currently, this installs version 2.0.5 which includes the bug I've detailed below.

@Vlad Zloteanu demonstrates that 1.0.5 does not include the bug. I have also tried with 1.0.5 and confirm that the bug does not exist in this version. People struggling with acts_as_taggable_on and owned tags on 2.x, rollback and wait for a fix..


For some reason, tags aren't showing up on a taggable object when an tagger is specified.

testing the post

class Post < ActiveRecord::Base
  acts_as_taggable_on :tags
  belongs_to :user
end

>> p = Post.first
=> #<Post id: 1, ...>
>> p.is_taggable?
=> true
>> p.tag_list = "foo, bar"
=> "foo, bar"
>> p.save
=> true
>> p.tags
=> [#<Tag id: 1, name: "foo">, #<Tag id: 2, name: "bar">]

testing the user

class User < ActiveRecord::Base
  acts_as_tagger
  has_many :posts
end

>> u = User.first
=> #<User id: 1, ...>
>> u.is_tagger?
=> true
>> u.tag(p, :with => "hello, world", :on => :tags)
=> true
>> u.owned_tags
=> [#<Tag id: 3, name: "hello">, #<Tag id: 4, name: "world">]

refresh the post

>> p = Post.first
=> #<Post id: 1 ...>
>> p.tags
=> [#<Tag id: 2, name: "bar">, #<Tag id: 1, name: "foo">]

Where's the hello and world tags? Miraculously, if I modify the database directly to set tagger_id and tagger_type to NULL, the two missing tags will show up. I suspect there's something wrong with my User model? What gives?


EDIT

Even stranger:

Post.tagged_with("hello")
#=> #<Post id: 1, ...>

It finds the post! So it can read the tag from the database! How come it's not showing up with Post#tags or Post#tag_list?

Was it helpful?

Solution

I recreated your project, using exactly the same classes.

This is my result:

>> Post.create
=> #<Post id: 1, created_at: "2010-05-18 09:16:36", updated_at: "2010-05-18 09:16:36">
>> p = Post.first
=> #<Post id: 1, created_at: "2010-05-18 09:16:36", updated_at: "2010-05-18 09:16:36">
>> p.is_taggable?
=> true
>> p.tag_list = "foo, bar"
=> "foo, bar"
>> p.save
=> true
>> p.tags
=> [#<Tag id: 1, name: "foo">, #<Tag id: 2, name: "bar">]
>> User.create
=> #<User id: 1, created_at: "2010-05-18 09:17:02", updated_at: "2010-05-18 09:17:02">
>> u = User.first
=> #<User id: 1, created_at: "2010-05-18 09:17:02", updated_at: "2010-05-18 09:17:02">
>> u.is_tagger?
=> true
>> u.tag(p, :with => "hello, world", :on => :tags)
=> true
>> u.owned_tags
=> [#<Tag id: 3, name: "hello">, #<Tag id: 4, name: "world">]
>> p = Post.first
=> #<Post id: 1, created_at: "2010-05-18 09:16:36", updated_at: "2010-05-18 09:16:36">
>> p.tags
=> [#<Tag id: 1, name: "foo">, #<Tag id: 2, name: "bar">, #<Tag id: 3, name: "hello">, #<Tag id: 4, name: "world">]

Therefore, I can not replicate your bug. I've tried it with both mysql and sqlite.

This is from my env file:

config.gem "mbleigh-acts-as-taggable-on", :source => "http://gems.github.com", :lib => "acts-as-taggable-on"

This is my gem version:

gem list | grep taggable
mbleigh-acts-as-taggable-on (1.0.5)

Can you post your gem version? Can you try to upgrade your gem? What DB are you using?

If it doesn't work, can you also post the output from tail -f log/development.log ?

EDIT: I'm using Rails 2.3.5

OTHER TIPS

mbleigh released a commit that resolve this problem. To obtain ALL the tags you can use owner_tags_on :

p = Post.first
p.owner_tags_on(nil, :tags )

This is the commit: http://github.com/mbleigh/acts-as-taggable-on/commit/3d707c25d45b5cc680cf3623d15ff59856457ea9

bye, Alessandro DS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top