更新しました
少し考えてみました。エラーの種類が少ない場合は、このようにしてみてはいかがでしょうか。
の最後の行routes.rb
に、
match '/my_segment/*path', :to => 'errors#not_found'
これは、定義されていない (通常は をスローするActionController::RoutingError
) パスと一致し、それをグローバル エラー ページにプッシュする必要があります。
上記のセグメントワイルドカードを使って遊んで、正しいパスを取得できます。これは、のような事前定義されたパスには影響しませんmydomain.com/controller1
。
以下は、よりきめ細かい制御方法です。
これにより、mydomain.com/some_controller/bad_params
def firstController < ApplicationController
def method_in_first_controller
# Do something here
rescue
@error = # Error object here
render :template=>"some_error_template", :status => :not_found # In specific action
end
end
def secondController < ApplicationController
rescue_from ActiveRecord::RecordNotFound, :with => :rescue_not_found # In secondController
def method_in_second_controller
# Do something
end
protected
def rescue_not_found
@error = # Error object here
render :template => 'some_error_template', :status => :not_found
end
end
def ApplicationController
rescue_from ActiveRecord::RecordNotFound, :with => :rescue_not_found # Globally
protected
def rescue_not_found
@error = # Error object here
render :template => 'application/not_found', :status => :not_found
end
end
リファラーを使用してもうまくいかないようです。昨日の悪い回答で申し訳ありません。