LoginSignup
19
18

More than 5 years have passed since last update.

Rails3.2でエラー画面を静的ファイルでなくcontrollerで処理する方法

Last updated at Posted at 2013-05-01

production環境下では404, 500などのエラーが発生した場合にpublicディレクトリの下にある静的ファイルが表示されるが、これをcontroller経由で処理できるようにする方法。
routingで表示するエラーを指定し、各メソッド、テンプレートを作成する。
有効にするには各環境で設定を変更する必要がある。

config/environments/*.rb
config.consider_all_requests_local = false
config.exceptions_app = self.routes
contig/routes.rb
match "/404", :to => "errors#not_found"
match "/500", :to => "errors#system_error"
errors_controller
class ErrorsController < ApplicationController
  def not_found
  end

  def system_error
  end
end

後はアクションに合わせて各テンプレートを用意する。

19
18
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
19
18