mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.96k stars 1.2k forks source link

Assign newly create tags to owner #982

Open chrisgeek opened 4 years ago

chrisgeek commented 4 years ago

Hi, great work on the gem, I am working with Active Admin and added the acts_as_taggable_on gem, problem is two models, templates and accounts, I want templates to be taggable while tags will be scoped to accounts. With Active Admin I have can create a tag without tagging it to template which is what I want, but the problem is, I need to be able to assign an account as the owner of the newly created tag, I have tried using this example from the wiki, @some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations) but it only means an owner can only be added after an object has been tagged but I want to add an owner after creating the tag. below is the code I where I tried to add an owner to the tag after creating it.

ActiveAdmin.register ActsAsTaggableOn::Tag, as: "Tag" do
controller do
    def create
      super
      acct = Account.last.tag(params[:acts_as_taggable_on_tag])
    end
  end
end

Account model

class Account < ApplicationRecord
  acts_as_tagger
end

Template Model

class ItemTemplate < ItemParent
  # after_save :set_tag_owner
  acts_as_taggable
end

Or does it mean a tag can't be assigned an owner unless it has been tagged to an object ?