I am using acts-as-taggable-on gem.
i want to use search both name as well as tags in single search field
my model
class User < ActiveRecord::Base
acts_as_taggable
attr_accessor: :name, :age, :country, tag_list
def self.search(search)
if search
where('name LIKE ?', "%#{search}%")
else
scoped
end
end
end
Controller
class UserAppsController < ApplicationController
def index
@users = User.search(params[:search])
//@users = User.tagged_with(params[:search])
end
end
Help me to solve this.
One way is to add both results one to another using + :
A better solution will be to change your search method in the model to return the full result:
but if you want to split the name search from the tag search, you can split them into scopes or something like that and then use it:
and in your search method:
btw if you want the name search to be case insensitive use something like: