Skip to content

Instantly share code, notes, and snippets.

@foliwe
Created March 3, 2017 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save foliwe/3e20d2df88040b55243f120c55cdca36 to your computer and use it in GitHub Desktop.
Save foliwe/3e20d2df88040b55243f120c55cdca36 to your computer and use it in GitHub Desktop.
search
class BooksController < ApplicationController
def index
@books = Book.all
end
def search
if params[:price].present? && params[:category].present?
@books = Book.where(category_id: params[:category]).where("price <= ?", params[:price])
elsif
params[:category].present?
@books = Book.where(category_id: params[:category])
elsif
params[:search].present?
@books = Book.where("title LIKE ?",params[:search])
elsif
params[:search].blank?
#"NO RESULT FOUND "
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment