Strange behavior with act_as_taggable_on

Edit

The Github instructions tell you to use the gemcutter source for the gem. This currently installs version 2.0.5, which includes an error, which I described in detail below.

@Vlad Zloteanu demonstrates that 1.0.5 does not include an error. I also tried with 1.0.5 and confirmed that there is no error in this version . People struggle with act_as_taggable_on and own tags on 2.x, roll back and wait for correction.


For some reason, tags are not displayed on the taggable if a tagger is specified.

message testing

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

user testing

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

update message

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

hello world? , , tagger_id tagger_type NULL, . , - User? ?


:

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

! , ! Post#tags Post#tag_list?

+3
2

, .

:

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

env :

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

gem:

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

gem? ? ?

, tail -f log/development.log?

EDIT: Rails 2.3.5

+3

mbleigh , . , owner_tags_on:

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

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

, ..

0

Source: https://habr.com/ru/post/1744874/


All Articles