Couple of comments on the beta gems with Routes support that were released today. Default Route I can''t seem to get the default route to work. I tried this: ActionController::Routing::Routes.draw do |map| map.connect '''', :controller => ''home'', :action => ''index'' map.connect '':controller/:action/:id'' end This doesn''t seem to work in Webrick. Requests for / still end up on the ''Welcome to Rails'' page instead of the Home#index controller. Errors I have a route like this: ActionController::Routing::Routes.draw do |map| map.connect ''/post/:post_id/comments'', :controller => ''post'', :action => ''comments'' map.connect '':controller/:action/:id'' end In Post#comments i made the mistake of using params[''id''] instead of params[''post_id''] and that resulted in a confusing ''Page not Found'' error. The log however showed the correct error. I think this should really end up as a server error (500). Also, I run this instance in the ''development'' environment, so I think it should simply show the error in the default rails way then. Other than that, good stuff! S.
> This doesn''t seem to work in Webrick. Requests for / still end up on > the ''Welcome to Rails'' page instead of the Home#index controller.That''s because it checks the file system first. And you probably have a default index.html file. Remove that and you can redirect from the root.> ActionController::Routing::Routes.draw do |map| > map.connect ''/post/:post_id/comments'', :controller => ''post'', :action > => ''comments'' > map.connect '':controller/:action/:id'' > end > > In Post#comments i made the mistake of using params[''id''] instead of > params[''post_id''] and that resulted in a confusing ''Page not Found'' > error. The log however showed the correct error.Are you getting other errors properly? That is, do you get the debug screen for syntax errors? If Rails doesn''t treat you as a local request, you''ll see non-descriptive errors like that.> Other than that, good stuff!Nicholas is the man. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://www.loudthinking.com/ -- Broadcasting Brain
On Feb 15, 2005, at 10:15 PM, David Heinemeier Hansson wrote:>> ActionController::Routing::Routes.draw do |map| >> map.connect ''/post/:post_id/comments'', :controller => ''post'', >> :action => ''comments'' >> map.connect '':controller/:action/:id'' >> end >> >> In Post#comments i made the mistake of using params[''id''] instead of >> params[''post_id''] and that resulted in a confusing ''Page not Found'' >> error. The log however showed the correct error. > > Are you getting other errors properly? That is, do you get the debug > screen for syntax errors? If Rails doesn''t treat you as a local > request, you''ll see non-descriptive errors like that.I just put a little typo in a rhtml file and got the standard error page with the info about the session/params/template. So it just seems to happen with routes as I described. S.
The trick is that it''s not a "Page not found" error, it''s a "Not found" error. Whatever query you''re doing based on the id is failing because you''re using id, not post_id, and this is throwing the "Not found" error to indicate that no record can be found. I agree that the display of this error could provide a more useful description. On 16/02/2005, at 6:13 PM, Stefan Arentz wrote:> > On Feb 15, 2005, at 10:15 PM, David Heinemeier Hansson wrote: > >>> ActionController::Routing::Routes.draw do |map| >>> map.connect ''/post/:post_id/comments'', :controller => ''post'', >>> :action => ''comments'' >>> map.connect '':controller/:action/:id'' >>> end >>> >>> In Post#comments i made the mistake of using params[''id''] instead of >>> params[''post_id''] and that resulted in a confusing ''Page not Found'' >>> error. The log however showed the correct error. >> >> Are you getting other errors properly? That is, do you get the debug >> screen for syntax errors? If Rails doesn''t treat you as a local >> request, you''ll see non-descriptive errors like that. > > I just put a little typo in a rhtml file and got the standard error > page with the info about the session/params/template. So it just seems > to happen with routes as I described. > > S. > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Feb 16, 2005, at 10:19 AM, Pete Yandell wrote:> The trick is that it''s not a "Page not found" error, it''s a "Not > found" error. Whatever query you''re doing based on the id is failing > because you''re using id, not post_id, and this is throwing the "Not > found" error to indicate that no record can be found.This is not true; Routes seem to capture any error. I just change Post.find() to Poooost.find() and I still get the Not Found error. This is extremely confusing and not appropriate for the development environment. The Routes module apparently reinvented the wheel for error handling. Which is wrong imo, as we already had that in place. All it has to do is dispatch to the right controller and let ActiveController::Base do it''s usual exception handling.> I agree that the display of this error could provide a more useful > description.I would really prefer the original style of error reporting. S.
This was a development snafu. I added a raise to rescues.rb when I was testing the changes made to that file. Unfortunately I forgot to take it out. I''ve put up a ticket and patch. http://dev.rubyonrails.com/ticket/647 My apologies for breaking this, and thanks for making me aware of this. -- Nicholas Seckar aka. Ulysses