Skip to content

Instantly share code, notes, and snippets.

@MaryKuz
Created March 28, 2019 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaryKuz/8c939121afb6eea91d626fd566f1edcb to your computer and use it in GitHub Desktop.
Save MaryKuz/8c939121afb6eea91d626fd566f1edcb to your computer and use it in GitHub Desktop.
Correct the .search_by method
def search_by params = {}
params = params.try(:symbolize_keys) || {}
collection = page(params[:page])
if params[:term].present?
collection = collection.where('name ILIKE ?', "#{ params[:term] }%")
end
if params[:name].present?
collection = collection.search(params[:name])
end
collection
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment