I am writing a Rails application, I want DRY to be just a little bit, and instead of calling my error class at the top of every controller I need, I placed it inside the module and simply turned on its module.
Work code (module):
module ApiException
class EmptyParameter < StandardError
end
end
Work code (controller):
include ApiException
rescue_from EmptyParameter, :with => :param_error
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
Here is my question using the command :with, how can I call a method inside my custom module?
Something like that: rescue_from EmptyParameter, :with => :EmptParameter.custom_class
source
share