I am using acts-as-taggable-on gem
i use single field to search by tag_name and user_name
User.rb
class User < ActiveRecord::Base
acts_as_taggable
attr_accessor: :user_name, :age, :country, tag_list
scope :tagged_with, lambda { |tag|
{
:joins => "INNER JOIN taggings ON taggings.taggable_id = user.id\
INNER JOIN tags ON tags.id = taggings.tag_id AND taggings.taggable_type = 'User'",
:conditions => ["tags.name = ?", tag],
:order => 'id ASC'
}
}
def self.search(search)
if search
where('name LIKE ?', "%#{search}%") + tagged_with(search)
else
scoped
end
end
end
But i have pagination issue while getting this as Array and i used "will_paginate/Array" in config/initializer/will_paginate.rb it doesn't work.
User controller
class UserController < ActionController::Base
def index
@users = User.search(params[:search]).paginate(:per_page => per_page, :page => params[:page])
end
Console.
User.search("best") => Should search by both tag_name and user_name and return ActiveRecord result.
i want to get the result of User.search("best") union with result of tag name User.tagged_with("best")
Can you help me to add this scopes as ActiveRecord relation to use pagination without issue.