From a39b0711eefb07fb75294a68d635fb1323d24cf3 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Oct 2023 12:36:21 -0400 Subject: Quotes can be submitted, although it is not encouraged --- app/controllers/quotes_controller.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'app/controllers/quotes_controller.rb') diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb index 58af7bb..f7445da 100644 --- a/app/controllers/quotes_controller.rb +++ b/app/controllers/quotes_controller.rb @@ -63,6 +63,12 @@ class QuotesController < ApplicationController @quote = Quote.new(quote_params) @quote.submitter = nil if @quote.submitter.empty? + unless @quote.valid? + flash.alert = "Error submitting quote." + render :new + return + end + if user_signed_in? @quote.state = :published @quote.save! @@ -70,8 +76,13 @@ class QuotesController < ApplicationController flash[:notice] = "Thank you for submitting your quote!" redirect_to @quote else - flash[:error] = "There was an error." - render :new + @quote.state = :pending + @quote.save! + + QuoteMailer.with(quote: @quote).pending_quote_email.deliver_later + + flash[:notice] = "Your quote has been submitted and is pending moderation." + redirect_to new_quote_url end end -- cgit 1.4.1