diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-21 00:55:24 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-21 00:55:24 -0400 |
commit | 5dddde5dee7beecfb6824b208c4fb86c781a27f9 (patch) | |
tree | ca3c8f15020d889c8aeb4ebcb9ba102abee98923 /app/controllers | |
parent | 96813a5e508a54257ef03be613a704f1f71af53d (diff) | |
download | thoughts-5dddde5dee7beecfb6824b208c4fb86c781a27f9.tar.gz thoughts-5dddde5dee7beecfb6824b208c4fb86c781a27f9.tar.bz2 thoughts-5dddde5dee7beecfb6824b208c4fb86c781a27f9.zip |
Added quote submission (and random)
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/quotes_controller.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb index fb5e33c..58af7bb 100644 --- a/app/controllers/quotes_controller.rb +++ b/app/controllers/quotes_controller.rb | |||
@@ -26,6 +26,11 @@ class QuotesController < ApplicationController | |||
26 | end | 26 | end |
27 | end | 27 | end |
28 | 28 | ||
29 | def random | ||
30 | picked = Quote.ids.sample | ||
31 | redirect_to quote_url(picked) | ||
32 | end | ||
33 | |||
29 | def tags | 34 | def tags |
30 | @tags = Quote.published.tag_counts_on(:tags) | 35 | @tags = Quote.published.tag_counts_on(:tags) |
31 | end | 36 | end |
@@ -51,6 +56,23 @@ class QuotesController < ApplicationController | |||
51 | end | 56 | end |
52 | 57 | ||
53 | def new | 58 | def new |
59 | @quote = Quote.new | ||
60 | end | ||
61 | |||
62 | def create | ||
63 | @quote = Quote.new(quote_params) | ||
64 | @quote.submitter = nil if @quote.submitter.empty? | ||
65 | |||
66 | if user_signed_in? | ||
67 | @quote.state = :published | ||
68 | @quote.save! | ||
69 | |||
70 | flash[:notice] = "Thank you for submitting your quote!" | ||
71 | redirect_to @quote | ||
72 | else | ||
73 | flash[:error] = "There was an error." | ||
74 | render :new | ||
75 | end | ||
54 | end | 76 | end |
55 | 77 | ||
56 | def upvote | 78 | def upvote |
@@ -94,4 +116,10 @@ class QuotesController < ApplicationController | |||
94 | end | 116 | end |
95 | end | 117 | end |
96 | end | 118 | end |
119 | |||
120 | private | ||
121 | |||
122 | def quote_params | ||
123 | params.require(:quote).permit(:content, :notes, :submitter, :tag_list) | ||
124 | end | ||
97 | end | 125 | end |