Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Forked from foliwe/searh.rb
Last active March 3, 2017 21:04
Show Gist options
  • Save tbuehlmann/83d5e54a4d371b70be4f27618042bedc to your computer and use it in GitHub Desktop.
Save tbuehlmann/83d5e54a4d371b70be4f27618042bedc to your computer and use it in GitHub Desktop.
search
class BooksController < ApplicationController
def index
@books = Book.all
end
def search
@books = Book.all
if params[:price].present?
@books = @books.where('price <= ?', params[:price])
end
if params[:category].present?
@books = @books.where(category_id: params[:category])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment