3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

エラーの内容に応じて表示するHTMLを変更する

Last updated at Posted at 2012-10-18

500.html以外を表示したい場合。

# /lib/exceptions.rb
module Exceptions
  class PaymentGatewayError < StandardError; end
end

# /app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  rescue_from Exceptions::PaymentGatewayError do |exception|
    render(:file => "#{Rails.root}/public/payment_error", :layout => false, :status => 500)
  end
end

# /public/payment_error.html
<html><body>決済エラー</body></html>

これでraise Exceptions::PaymentGatewayErrorとかってやるとpayment_error.htmlが表示される。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?