Class: Admin::TagsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/tags_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/admin/tags_controller.rb', line 4

def index
  term = params[:term]
  context = params[:context] || "tags"
  
  @tag_names = if(term && term.size >= 3)
    condition = ActsAsTaggableOn::Tag.arel_table[:name].matches("%#{term}%")
    tags = ActsAsTaggableOn::Tag.joins("JOIN taggings on taggings.tag_id = tags.id").where(condition)
    
    if context
      tags = tags.where("taggings.context" => context)
    end
    
    tags.pluck(:name)
  end || []

  render :json => @tag_names
end