diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-03-04 22:47:31 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-03-04 22:47:31 -0500 |
commit | f3e3735c7efe9ba8fcc0e58cda4ee3996e12d38e (patch) | |
tree | d1913cb1ff747d9202ff9efb34a4e12c982163b6 /app | |
parent | 49c58dc5de3688d842025b83cbc91a69ef621641 (diff) | |
download | thoughts-f3e3735c7efe9ba8fcc0e58cda4ee3996e12d38e.tar.gz thoughts-f3e3735c7efe9ba8fcc0e58cda4ee3996e12d38e.tar.bz2 thoughts-f3e3735c7efe9ba8fcc0e58cda4ee3996e12d38e.zip |
Add quotes search
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/quotes_controller.rb | 14 | ||||
-rw-r--r-- | app/models/quote.rb | 9 | ||||
-rw-r--r-- | app/views/quotes/search_form.html.haml | 6 |
3 files changed, 29 insertions, 0 deletions
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 | |||
30 | end | 30 | end |
31 | end | 31 | end |
32 | 32 | ||
33 | def search_form | ||
34 | @q = Quote.published.ransack | ||
35 | end | ||
36 | |||
37 | def search | ||
38 | @quotes = Quote.published.ransack(params[:q]).result(distinct: true).paginate(page: params[:page], per_page: 10) | ||
39 | |||
40 | respond_to do |format| | ||
41 | format.html { render :list } | ||
42 | format.json { render :json => @quotes } | ||
43 | format.xml { render :xml => @quotes } | ||
44 | end | ||
45 | end | ||
46 | |||
33 | def random | 47 | def random |
34 | picked = Quote.where(state: :published).ids.sample | 48 | picked = Quote.where(state: :published).ids.sample |
35 | redirect_to quote_url(picked) | 49 | redirect_to quote_url(picked) |
diff --git a/app/models/quote.rb b/app/models/quote.rb index 3301667..b1d25b4 100644 --- a/app/models/quote.rb +++ b/app/models/quote.rb | |||
@@ -36,4 +36,13 @@ class Quote < ApplicationRecord | |||
36 | def has_tags? | 36 | def has_tags? |
37 | !tags.empty? | 37 | !tags.empty? |
38 | end | 38 | end |
39 | |||
40 | def self.ransackable_attributes(auth_object = nil) | ||
41 | ["content", "notes"] | ||
42 | end | ||
43 | |||
44 | def self.ransackable_associations(auth_object = nil) | ||
45 | [] | ||
46 | end | ||
47 | |||
39 | end | 48 | end |
diff --git a/app/views/quotes/search_form.html.haml b/app/views/quotes/search_form.html.haml new file mode 100644 index 0000000..74cdd20 --- /dev/null +++ b/app/views/quotes/search_form.html.haml | |||
@@ -0,0 +1,6 @@ | |||
1 | %h3 Search | ||
2 | = search_form_for @q, url: search_quotes_url do |f| | ||
3 | .form-field | ||
4 | = f.label :content_or_notes_cont, "Query:" | ||
5 | = f.search_field :content_or_notes_cont | ||
6 | .form-field= f.submit | ||