Search code examples
ruby-on-railsdeviseacts-as-taggable-onrailscasts

Using acts_as_tagger in User model with Devise


After watching RailsCast #382 on tagging with acts-as-taggable-on I have one question.

When using Devise for authentication is there any way to set up tag ownership using current_user?

class User < ActiveRecord::Base
  acts_as_tagger

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :remember_me
end

I added acts_as_tagger to the User model per the acts-as-taggable-on documentation.

class Object < ActiveRecord::Base
  acts_as_taggable
end

I set acts_as_taggable on the Object model.

With this setup I am still seeing tagger_id set to nil in the logs when I create a new object with tags.


Solution

  • You have to use the user as subject to the tagging action:

    current_user.tag(@some_object, :with => "paris, normandy")
    

    so you have to tag in the controller.