开发者

Rails 3 Routing Question

Why in Rails 3 do you have to uncomment match ':controller(/:action(/:id(.:format)))' (as seen in this Hello World article) to make the index method of the hello controller be called when you go to http://localhost:3000/hello? Can somebody please explain why we have to do this in Rails 3 but not Rails 2, and is this开发者_开发百科 a normal thing for Rails 3 or is it some kind of hack?


That particular match is sort of a catch-all for any requests that haven't already been defined.

Ideally you should be using Resource Routing, but that matcher still exists as legacy support.

It's commented out by default because Rails assumes that if a user attempts to access a route that you didn't explicitly define, it should cause a 404 error instead of a 500 error, which is what would happen if I tried to access http://localhost:3000/hello with that matcher enabled, because there's no 'hello' controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜