diff options
| -rw-r--r-- | app/controllers/quotes_controller.rb | 15 | ||||
| -rw-r--r-- | app/mailers/quote_mailer.rb | 7 | ||||
| -rw-r--r-- | app/views/quote_mailer/pending_quote_email.html.haml | 12 | ||||
| -rw-r--r-- | app/views/quote_mailer/pending_quote_email.text.erb | 15 | 
4 files changed, 47 insertions, 2 deletions
| 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 | |||
| 63 | @quote = Quote.new(quote_params) | 63 | @quote = Quote.new(quote_params) | 
| 64 | @quote.submitter = nil if @quote.submitter.empty? | 64 | @quote.submitter = nil if @quote.submitter.empty? | 
| 65 | 65 | ||
| 66 | unless @quote.valid? | ||
| 67 | flash.alert = "Error submitting quote." | ||
| 68 | render :new | ||
| 69 | return | ||
| 70 | end | ||
| 71 | |||
| 66 | if user_signed_in? | 72 | if user_signed_in? | 
| 67 | @quote.state = :published | 73 | @quote.state = :published | 
| 68 | @quote.save! | 74 | @quote.save! | 
| @@ -70,8 +76,13 @@ class QuotesController < ApplicationController | |||
| 70 | flash[:notice] = "Thank you for submitting your quote!" | 76 | flash[:notice] = "Thank you for submitting your quote!" | 
| 71 | redirect_to @quote | 77 | redirect_to @quote | 
| 72 | else | 78 | else | 
| 73 | flash[:error] = "There was an error." | 79 | @quote.state = :pending | 
| 74 | render :new | 80 | @quote.save! | 
| 81 | |||
| 82 | QuoteMailer.with(quote: @quote).pending_quote_email.deliver_later | ||
| 83 | |||
| 84 | flash[:notice] = "Your quote has been submitted and is pending moderation." | ||
| 85 | redirect_to new_quote_url | ||
| 75 | end | 86 | end | 
| 76 | end | 87 | end | 
| 77 | 88 | ||
| diff --git a/app/mailers/quote_mailer.rb b/app/mailers/quote_mailer.rb new file mode 100644 index 0000000..1f3bddd --- /dev/null +++ b/app/mailers/quote_mailer.rb | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | class QuoteMailer < ApplicationMailer | ||
| 2 | def pending_quote_email | ||
| 3 | @quote = params[:quote] | ||
| 4 | # again, this is odd | ||
| 5 | mail(to: User.first.email, subject: "[Four Island] New quote pending moderation") | ||
| 6 | end | ||
| 7 | end | ||
| diff --git a/app/views/quote_mailer/pending_quote_email.html.haml b/app/views/quote_mailer/pending_quote_email.html.haml new file mode 100644 index 0000000..fff825d --- /dev/null +++ b/app/views/quote_mailer/pending_quote_email.html.haml | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | %p | ||
| 2 | A new quote has been submitted for moderation. | ||
| 3 | - unless @quote.submitter.nil? | ||
| 4 | %p | ||
| 5 | It was submitted by: | ||
| 6 | = succeed "." do | ||
| 7 | = @quote.submitter | ||
| 8 | %p The body of the quote: | ||
| 9 | %pre= @quote.content | ||
| 10 | %p | ||
| 11 | Submitted: | ||
| 12 | = @quote.created_at.strftime("%B #{@quote.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") | ||
| diff --git a/app/views/quote_mailer/pending_quote_email.text.erb b/app/views/quote_mailer/pending_quote_email.text.erb new file mode 100644 index 0000000..818fc4a --- /dev/null +++ b/app/views/quote_mailer/pending_quote_email.text.erb | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | A new quote has been submitted for moderation. | ||
| 2 | |||
| 3 | <% unless @quote.submitter.nil? %> | ||
| 4 | It was submitted by: <%= @quote.submitter %>. | ||
| 5 | |||
| 6 | <% end %> | ||
| 7 | Here is the quote: | ||
| 8 | |||
| 9 | --- | ||
| 10 | |||
| 11 | <%= @quote.content %> | ||
| 12 | |||
| 13 | --- | ||
| 14 | |||
| 15 | Posted: <%= @quote.created_at.strftime("%B #{@quote.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") %> | ||
