From 5dddde5dee7beecfb6824b208c4fb86c781a27f9 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Oct 2023 00:55:24 -0400 Subject: Added quote submission (and random) --- app/controllers/quotes_controller.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'app/controllers') 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 end end + def random + picked = Quote.ids.sample + redirect_to quote_url(picked) + end + def tags @tags = Quote.published.tag_counts_on(:tags) end @@ -51,6 +56,23 @@ class QuotesController < ApplicationController end def new + @quote = Quote.new + end + + def create + @quote = Quote.new(quote_params) + @quote.submitter = nil if @quote.submitter.empty? + + if user_signed_in? + @quote.state = :published + @quote.save! + + flash[:notice] = "Thank you for submitting your quote!" + redirect_to @quote + else + flash[:error] = "There was an error." + render :new + end end def upvote @@ -94,4 +116,10 @@ class QuotesController < ApplicationController end end end + + private + + def quote_params + params.require(:quote).permit(:content, :notes, :submitter, :tag_list) + end end -- cgit 1.4.1