Web サイトにカスタム エラー ページを設定しようとしています。PerfectLine ブログのガイドラインに従っています。
コントローラーは存在するが、id が存在しない場合に機能します。たとえば、ブログ コントローラーがあり、id 4 が存在しません。カスタムエラーページを表示します
ただし、コントローラ自体が存在しない場合は存在しません。たとえば、数値 ID を持つランダム コントローラーを入力すると、カスタム エラー ページを再ルーティングするためにアプリケーション コントローラーで設定したメソッドによってキャッチされません。この場合、私は
ActionController::RoutingError (No route matches "/randomcontrollername"):
ターミナルとレールに付属のデフォルトのエラーページで。
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, :with => :render_error
rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
rescue_from ActionController::RoutingError, :with => :render_not_found
rescue_from ActionController::UnknownController, :with => :render_not_found
rescue_from ActionController::UnknownAction, :with => :render_not_found
end
private
def render_not_found(exception)
render :template => "/error/404.html.erb", :status => 404
end
def render_error(exception)
render :template => "/error/500.html.erb", :status => 500
end
end
手伝っていただけませんか。ありがとう。