On Mon, Sep 06, 2010 at 10:39:21PM -0700, dev2 wrote: > I modified my controllers/exceptions.rb file. I added an action for > my exception, but obviously this isn't enough to make it work. in my > Things controller I "raise FileMissing" and I get the error > "undefined constant Things:FileMissing". What do I need to do to > make this work? > Thanks! > > class Exceptions < Merb::Controller > > # handle NotFound exceptions (404) > def not_found > render :format => :html > end > > # handle NotAcceptable exceptions (406) > def not_acceptable > render :format => :html > end > > def file_missing > render :format => :html > end > end >
You need to first create the exception class for merb to route it properly. Look at exceptions.rb [1]. Basically, you will want to create your exception class (in this case FileMissing) and have it inherit from an existing controller exception. Starting from line 242 [2] is a list of all the exceptions with their status codes. You will probably want to raise something in the 4xx range. So it would look something like: class FileMissing < Merb::ControllerExceptions::BadRequest; end That will send a status code of 400 anytime you raise FileMissing, along with rendering the action as you have created it in your exceptions controller. [1] http://github.com/merb/merb/blob/master/merb-core/lib/merb-core/controller/exceptions.rb#L124 [2] http://github.com/merb/merb/blob/master/merb-core/lib/merb-core/controller/exceptions.rb#L242 > -- > You received this message because you are subscribed to the Google Groups > "merb" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/merb?hl=en. > -- -jonah -- You received this message because you are subscribed to the Google Groups "merb" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/merb?hl=en.
