3
私はRailsアプリケーションを作成していますが、私はそれを必要とする各コントローラの上部に私のカスタムエラークラスを呼び出すのではなく、それをモジュールの中に置き、そのモジュールだけを含んでいました。Rails 3 rescue_from、カスタムモジュールを使用して作業しています
の作業コード(モジュール):
module ApiException
class EmptyParameter < StandardError
end
end
の作業コード(コントローラー):私は私のカスタムモジュール内のメソッドを呼び出す方法:with
コマンドを使用して、私の質問は、
# include custom error exception classes
include ApiException
rescue_from EmptyParameter, :with => :param_error
# rescure record_not_found with a custom XML response
rescue_from ActiveRecord::RecordNotFound, :with => :active_record_error
def param_error(e)
render :xml => "<error>Malformed URL. Exception: #{e.message}</error>"
end
def active_record_error(e)
render :xml => "<error>No records found. Exception: #{e.message}</error>"
end
です?このような
何か:rescue_from EmptyParameter, :with => :EmptParameter.custom_class
はFYIそのrescue_fromはまだ似たような自分自身をしようとRailsの3で動作していません。 lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror – JohnMetta