0
votes

I am using the acts-as-taggable-on gem which can be found here https://github.com/mbleigh/acts-as-taggable-on. I do not have a Tag nor Taggings model in my app/models because the functionality comes directly from the gem. Tags are created fine and everything. However, I want to be able to assign the user_id column in the tags table to the current user when a tag is being created. Something like :

 #pseudocode 
 before_save { tag.user_id = current_user.id }

I though about first extending the tag model but I have no idea on how to do it in this case as the tag class is defined within the gem (I think). I guess my question is how do I implement a before_save or after_save callback that will make sure that when a tag is being created with acts-as-taggable-on, that the tag.user_id is automatically assigned to current_user.id ? This is what I have tried but it seems not to be working. I tried to add another tag model (not the one defined somewhere in the gem' s modules):

class Tag < ActsAsTaggableOn::Tag
   before_create :assign_user_id

   def assign_user_id
      self.user_id = current_user.id
   end

end

Thanks for your help !!!

1
Hi, how did you resolve this? I happen to be facing the same challenge.chrisgeeq

1 Answers

0
votes

acts-as-taggable-on provides Tag Ownership. An example from https://github.com/mbleigh/acts-as-taggable-on:

class User < ActiveRecord::Base
  acts_as_tagger
end

class Photo < ActiveRecord::Base
  acts_as_taggable_on :locations
end

@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)