Created
March 3, 2017 20:57
-
-
Save foliwe/3e20d2df88040b55243f120c55cdca36 to your computer and use it in GitHub Desktop.
search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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