Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 342
Oliver Avatar asked Jul 30 '18 19:07

Oliver


1 Answers

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
like image 96
Oliver Avatar answered Nov 18 '22 22:11

Oliver