怪异的行为与acts_as_taggable_on

时间:2022-08-03 17:26:40

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.

Github上的说明指导你使用宝石切割源。目前,这个版本安装了2.0.5,其中包含了我下面详细介绍的bug。

@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..

@Vlad Zloteanu演示了1.0.5不包含bug。我也尝试了1.0.5,并确认这个版本中不存在bug。人们在acts_as_taggable_on和2上拥有标签上苦苦挣扎。回滚并等待修复。


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?

hello和world标签在哪里?神奇的是,如果我直接修改数据库,将tagger_id和tagger_type设置为NULL,就会出现两个丢失的标记。我怀疑我的用户模型有问题?到底发生了什么事?


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?

它发现这个职位!这样它就可以从数据库中读取标签了!为什么它没有出现在Post#标签或Post#tag_list中呢?

2 个解决方案

#1


3  

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.

因此,我无法复制你的错误。我用mysql和sqlite都试过了。

This is from my env file:

这是我的env文件:

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

配置。gem " mbleighi -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?

你能发布你的宝石版本吗?你能升级你的宝石吗?你用什么DB ?

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

如果它不工作,你也可以发布来自tail -f日志/开发的输出。日志吗?

EDIT: I'm using Rails 2.3.5

编辑:我使用的是Rails 2.3.5

#2


0  

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

mbleigh发布了一个解决这个问题的承诺。要获取所有可以使用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

这是提交:http://github.com/mbleigh/acts-as-taggable-on/commit/3d707c25d45b5cc680cf3623d15ff59856457ea9。

bye, Alessandro DS

再见,亚历山德罗DS

#1


3  

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.

因此,我无法复制你的错误。我用mysql和sqlite都试过了。

This is from my env file:

这是我的env文件:

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

配置。gem " mbleighi -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?

你能发布你的宝石版本吗?你能升级你的宝石吗?你用什么DB ?

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

如果它不工作,你也可以发布来自tail -f日志/开发的输出。日志吗?

EDIT: I'm using Rails 2.3.5

编辑:我使用的是Rails 2.3.5

#2


0  

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

mbleigh发布了一个解决这个问题的承诺。要获取所有可以使用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

这是提交:http://github.com/mbleigh/acts-as-taggable-on/commit/3d707c25d45b5cc680cf3623d15ff59856457ea9。

bye, Alessandro DS

再见,亚历山德罗DS