【发布时间】:2014-09-03 12:31:45
【问题描述】:
环境
- 铁路 3.1
- Ruby 1.9.1
我已经尝试过application_controller,但这似乎不起作用。
我可能做错了什么?
rescue_from ArgumentError do |exception|
flash.now[:error] = "Arguments for your request are incorrect"
#ExceptionNotifier::Notifier.background_exception_notification(exception).deliver if Rails.env.production?
redirect_to root_url, :alert => exception.message
end
我正在尝试处理的异常
A ArgumentError occurred in marketplace#index:
invalid byte sequence in UTF-8
.bundle/gems/ruby/1.9.1/gems/rack-1.4.5/lib/rack/utils.rb:104:in `normalize_params'
或
A ArgumentError occurred in connect#index:
invalid %-encoding (%u2713)
.bundle/gems/ruby/1.9.1/gems/rack-1.4.5/lib/rack/backports/uri/common_192.rb:46:in `decode_www_form_component'
【问题讨论】:
-
请在
raise ArgumentError发帖。如果是你的raiseing. -
您问题中的 2 个错误似乎来自机架中间件。它们在到达 rails 应用程序之前出现在堆栈中,因此您的 application_controller 永远不会知道这些异常。检查这个stackoverflow.com/questions/6501451/…,也许这个github.com/hassox/rack-rescue
-
观看此 railscast - railscasts.com/episodes/53-handling-exceptions-revised
标签: ruby-on-rails ruby exception