I''m using camping with reststop to do a html front end for sending pre-defined messages to different devices (puts will work) depending on the time (will parse cron). No real deadline. Works great up to now, much fun, forgot to sleep. Problem is when I pass a URL of the form /device/1/ping without a "Ping" controller method. It will send me a "501 Not Implemented". Interestingly enough, /device/1/1/ping will give me "404 Not Found" which I have properly handled. So my question are: In what part of the code can I catch the 501? How can I implement a catch-all controller method? Who''s giving me the nicely formated web page when the 501''s happening? Where could I have found that out? If I stop using reststop, will the problem go away? Attached is what I have worked up till now. Has a postamble, will work with webrick. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/camping-list/attachments/20080223/b945c1da/attachment-0001.html -------------- next part -------------- A non-text attachment was scrubbed... Name: ctd.rb Type: application/octet-stream Size: 4330 bytes Desc: not available Url : http://rubyforge.org/pipermail/camping-list/attachments/20080223/b945c1da/attachment-0001.obj
Hi, i gave a quick look at the code and it seems you need to work out the route for "ping" on the Devices class. I''m not using reststop, but went to check it out. http://reststop.rubyforge.org/classes/Camping/Controllers.src/M000011.html def no_method(e) _error("No controller method responds to this route!", 501, e) end def not_found(e) _error("Record not found!", 404, e) end Seems those 501 are being delivered by reststop. http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html "10.5.2 501 Not Implemented The server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource. " In Reststop: "Calling REST "<resource name>" creates a controller with the appropriate routes and maps your REST methods to standard Camping controller mehods. This is meant to be used in your Controllers module in place of R <routes>." You''l need to specify those possible routes probably: # GET /devices/1/ping def ping(id) ... end If i well understood, you''d like to have a /devices/1/(\w+) route that reststop could parse. It is not a case solved by a ''prefix''. If you knew the possible methods, you''d implement them. In this case, i''d use Camping standard Routes, where you are free to specify what you want by the use of RegExp''s. Or... you can try to change Reststop yourself ;) on your own risk, following or not the REST architecture :) Start by redirecting that error message to a specific Route of yours. /lib/reststop.rb if e.message =~ /no such method/ return no_method(e) # <== act here ;) else raise e end ...or even a bit above, in the protected block under send(custom_action...) pedro mg On 2/23/08, Albert Ng <twinwing at gmail.com> wrote:> I''m using camping with reststop to do a html front end for sending > pre-defined messages to different devices (puts will work) depending on the > time (will parse cron). No real deadline. > > Works great up to now, much fun, forgot to sleep. > > Problem is when I pass a URL of the form /device/1/ping without a "Ping" > controller method. It will send me a "501 Not Implemented". Interestingly > enough, /device/1/1/ping will give me "404 Not Found" which I have properly > handled. > > So my question are: > In what part of the code can I catch the 501? > How can I implement a catch-all controller method? > Who''s giving me the nicely formated web page when the 501''s happening? > Where could I have found that out? > If I stop using reststop, will the problem go away? > > Attached is what I have worked up till now. Has a postamble, will work with > webrick. > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > >-- pedro mg http://blog.tquadrado.com
Thanks for the advice Pedro, but unfortunately I''ve gone back to using the regular Camping paths. It''s less RESTfull, but more robust. if I was to call app/1/k, markaby (?) would show me the cookie name, same with (i) for italic 1, (b) for bold 1, and a few others. On Sun, Feb 24, 2008 at 12:38 AM, pedro mg <seti at tquadrado.com> wrote:> Hi, > > i gave a quick look at the code and it seems you need to work out the > route for "ping" on the Devices class. I''m not using reststop, but > went to check it out. > > http://reststop.rubyforge.org/classes/Camping/Controllers.src/M000011.html > > def no_method(e) > _error("No controller method responds to this route!", 501, e) > end > > def not_found(e) > _error("Record not found!", 404, e) > end > > Seems those 501 are being delivered by reststop. > ... > Or... you can try to change Reststop yourself ;) on your own risk, > following or not the REST architecture :)> pedro mg > http://blog.tquadrado.com > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/camping-list/attachments/20080225/b0a53d8f/attachment.html
not that regular camping paths are anything less than awesome On Mon, Feb 25, 2008 at 10:36 AM, Albert Ng <twinwing at gmail.com> wrote:> Thanks for the advice Pedro, but unfortunately I''ve gone back to using the > regular Camping paths. It''s less RESTfull, but more robust. > > if I was to call app/1/k, markaby (?) would show me the cookie name, same > with (i) for italic 1, (b) for bold 1, and a few others. > > On Sun, Feb 24, 2008 at 12:38 AM, pedro mg <seti at tquadrado.com> wrote: > > > Hi, > > > > i gave a quick look at the code and it seems you need to work out the > > route for "ping" on the Devices class. I''m not using reststop, but > > went to check it out. > > > > > > http://reststop.rubyforge.org/classes/Camping/Controllers.src/M000011.html > > > > def no_method(e) > > _error("No controller method responds to this route!", 501, e) > > end > > > > def not_found(e) > > _error("Record not found!", 404, e) > > end > > > > Seems those 501 are being delivered by reststop. > > ... > > Or... you can try to change Reststop yourself ;) on your own risk, > > following or not the REST architecture :) > > > > > pedro mg > > http://blog.tquadrado.com > > _______________________________________________ > > Camping-list mailing list > > Camping-list at rubyforge.org > > http://rubyforge.org/mailman/listinfo/camping-list > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/camping-list/attachments/20080225/8736e0f3/attachment.html