3

编辑

Github 上的说明指导您使用 gemcutter 源代码。目前,这安装了 2.0.5 版,其中包括我在下面详述的错误。

@Vlad Zloteanu 证明 1.0.5 不包含该错误。我也尝试过 1.0.5 并确认此版本中存在该错误。人们在 2.x 上为acts_as_taggable_on 和拥有标签而苦苦挣扎,回滚并等待修复..


出于某种原因,当指定标记器时,标记不会显示在可标记对象上。

测试帖子

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">]

测试用户

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">]

刷新帖子

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

helloworld标签在哪里?神奇的是,如果我直接将数据库修改为 settagger_idtagger_typeto NULL,两个缺失的标签就会出现。我怀疑我的User模型有问题?是什么赋予了?


编辑

更陌生:

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

它找到了帖子!所以它可以从数据库中读取标签!为什么它没有出现Post#tagsor Post#tag_list

4

2 回答 2

3

我使用完全相同的类重新创建了您的项目。

这是我的结果:

>> 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">]

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

这是来自我的环境文件:

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

这是我的宝石版本:

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

你能发布你的gem版本吗?您可以尝试升级您的宝石吗?你用的是什么数据库?

如果它不起作用,您还可以发布输出tail -f log/development.log吗?

编辑:我正在使用 Rails 2.3.5

于 2010-05-18T09:21:58.367 回答
0

mbleigh 发布了解决此问题的提交。要获取所有标签,您可以使用 owner_tags_on :

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

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

再见,亚历山德罗 DS

于 2010-06-26T16:35:00.363 回答