diff options
-rw-r--r-- | app/controllers/quotes_controller.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb index f7445da..cad7dfd 100644 --- a/app/controllers/quotes_controller.rb +++ b/app/controllers/quotes_controller.rb | |||
@@ -1,4 +1,6 @@ | |||
1 | class QuotesController < ApplicationController | 1 | class QuotesController < ApplicationController |
2 | protect_from_forgery with: :null_session, if: -> { request.format.json? or request.format.xml? } | ||
3 | |||
2 | def index | 4 | def index |
3 | @quote = Quote.find(310) | 5 | @quote = Quote.find(310) |
4 | @qnumber = Quote.published.count | 6 | @qnumber = Quote.published.count |
@@ -65,7 +67,13 @@ class QuotesController < ApplicationController | |||
65 | 67 | ||
66 | unless @quote.valid? | 68 | unless @quote.valid? |
67 | flash.alert = "Error submitting quote." | 69 | flash.alert = "Error submitting quote." |
68 | render :new | 70 | |
71 | respond_to do |format| | ||
72 | format.html { render :new } | ||
73 | format.json { render json: { error: "Error submitting quote." }, status: :bad_request } | ||
74 | format.xml { render xml: { error: "Error submitting quote." }, status: :bad_request } | ||
75 | end | ||
76 | |||
69 | return | 77 | return |
70 | end | 78 | end |
71 | 79 | ||
@@ -74,7 +82,11 @@ class QuotesController < ApplicationController | |||
74 | @quote.save! | 82 | @quote.save! |
75 | 83 | ||
76 | flash[:notice] = "Thank you for submitting your quote!" | 84 | flash[:notice] = "Thank you for submitting your quote!" |
77 | redirect_to @quote | 85 | respond_to do |format| |
86 | format.html { redirect_to @quote } | ||
87 | format.json { render json: @quote } | ||
88 | format.xml { render xml: @quote } | ||
89 | end | ||
78 | else | 90 | else |
79 | @quote.state = :pending | 91 | @quote.state = :pending |
80 | @quote.save! | 92 | @quote.save! |
@@ -82,7 +94,11 @@ class QuotesController < ApplicationController | |||
82 | QuoteMailer.with(quote: @quote).pending_quote_email.deliver_later | 94 | QuoteMailer.with(quote: @quote).pending_quote_email.deliver_later |
83 | 95 | ||
84 | flash[:notice] = "Your quote has been submitted and is pending moderation." | 96 | flash[:notice] = "Your quote has been submitted and is pending moderation." |
85 | redirect_to new_quote_url | 97 | respond_to do |format| |
98 | format.html { redirect_to new_quote_url } | ||
99 | format.json { render json: @quote } | ||
100 | format.xml { render xml: @quote } | ||
101 | end | ||
86 | end | 102 | end |
87 | end | 103 | end |
88 | 104 | ||