From f3e3735c7efe9ba8fcc0e58cda4ee3996e12d38e Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 4 Mar 2025 22:47:31 -0500 Subject: Add quotes search --- app/controllers/quotes_controller.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb index d4800cb..468f6ea 100644 --- a/app/controllers/quotes_controller.rb +++ b/app/controllers/quotes_controller.rb @@ -30,6 +30,20 @@ class QuotesController < ApplicationController end end + def search_form + @q = Quote.published.ransack + end + + def search + @quotes = Quote.published.ransack(params[:q]).result(distinct: true).paginate(page: params[:page], per_page: 10) + + respond_to do |format| + format.html { render :list } + format.json { render :json => @quotes } + format.xml { render :xml => @quotes } + end + end + def random picked = Quote.where(state: :published).ids.sample redirect_to quote_url(picked) -- cgit 1.4.1