簡體   English   中英

使用acts_as_taggable_on的奇怪行為

[英]weird behavior with acts_as_taggable_on

編輯

Github上的說明指示您使用gem的gemcutter源。 目前,這將安裝2.0.5版,其中包含我在下面詳述的錯誤。

@Vlad Zloteanu證明1.0.5不包含bug。 我也試過1.0.5並確認此版本中存在該錯誤。 人們在2.x上掙扎着act_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標簽在哪里? 奇跡般地,如果我直接修改數據庫以將tagger_idtagger_type設置為NULL ,則會顯示兩個缺失的標記。 我懷疑我的User模型有問題嗎? 是什么賦予了?


編輯

更奇怪的是:

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

它找到了帖子! 所以它可以從數據庫中讀取標簽! 怎么沒有出現Post#tagsPost#tag_list

我使用完全相同的類重新創建了您的項目。

這是我的結果:

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

因此,我無法復制你的bug。 我已經嘗試過mysql和sqlite。

這是我的env文件:

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)

你可以發布你的寶石版嗎? 你能嘗試升級你的寶石嗎? 你用的是什么數據庫?

如果它不起作用,你還可以發布tail -f log/development.log的輸出嗎?

編輯:我正在使用Rails 2.3.5

mbleigh發布了一個解決此問題的提交。 要獲取所有標簽,您可以使用owner_tags_on:

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

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

再見,Alessandro DS

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM