about summary refs log tree commit diff stats
path: root/app/controllers/quotes_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/quotes_controller.rb')
-rw-r--r--app/controllers/quotes_controller.rb28
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
97end 125end