Oliver
Oliver

Reputation: 851

acts-as-taggable-on use kind of scope (tagger?) and context

My Application uses acts-as-taggable-on to tag Content. The content belongs_to a Company.

Now all created tags should belong to the used company and not be visible to other companies.

How can i solve this with acts-as-taggable-on? As context i currently use :content. Is in my case the company the Tagger (owner)?

Thanks for clarification.

Upvotes: 5

Views: 162

Answers (1)

Oliver
Oliver

Reputation: 851

I solved it by declaring Company as the tagger.

class Company < ApplicationRecord
  acts_as_tagger
end

Controller action looks like the following:

def create
  if params[:content].has_key?(:content_tag_list)
    content_tag_list = params[:content][:content_tag_list]
    params[:content].delete(:content_tag_list)
  end

  @content = Content.new(content_params)
  if @content.save
    if content_tag_list
      @content.company.tag(@content, with: content_tag_list, on: :content_tags)
    end
    redirect_back fallback_location: your_path
  else
    render :new
  end
end

Upvotes: 4

Related Questions