3
我正在寫一個Rails應用程序,我只想幹一點點,而不是調用我需要它在每個控制器的頂部我的自定義錯誤類,I將其放置在模塊內部幷包含該模塊。Rails 3 rescue_from,並與自定義模塊
工作代碼(模塊):
module ApiException
class EmptyParameter < StandardError
end
end
工作代碼(控制器):
# 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
這裏是我的問題,使用:with
命令,怎麼會我叫我的自定義模塊內部的方法?
事情是這樣的:rescue_from EmptyParameter, :with => :EmptParameter.custom_class
僅供參考,這種rescue_from仍然沒有對Rails 3的工作嘗試做同樣的事情自己:https://開頭的軌道。 lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror – JohnMetta 2011-05-18 19:20:24