| home | resources | search | news | join | members: 6959 |
Hiveminds | Wed, 2005-08-17 22:20 tags: Routing is a pure-Ruby replacement for mod_rewrite. Routes that can navigate through URLs like this example: controller/action/params while finding specific controls and actions mapped to parts of the URL. This makes Rails URLs more configurable and to divorces RubyOnRails from the mod_rewrite requirement. Routes are individual rules that map matching URLs to specific controllers and actions. They are configured in the config/routes.rb file. Routes by ExampleHere are all the routes, and below a brief explanation of each:
# 1 /
# 2 /view/scott/my-first-post
# 3 /2005/02/24, /2005/02, /2005
# 4 /scott/2005/02/24, /scott/2005/02, /scott/2005
# 5 /tag/ruby+on+rails
# 6 /reply/23
# 7 /reply/23/comment/4
# 8 /drafts
# 9 /me
# 10 /links
# 11 /css
# 12 everything elseRoute 1This route just sets the default controller, so that going to http://foo.com/ will give you /post/index. Route 2 In trunk, a post has been given a slug for use in a url. What this route does is take you right to the post with that slug owned by a specific user. The user must be there in case two users have identically titled posts. Route 3 This allows one to look at posts from a specific year, month, or day. This route covers all posts for all users. Route 4 This is the same as route 3, but it limits the search to a specific user. Route 5 This cleans up the URL to find all posts with a specific tag. While I’m writing this I realize I should also add a route to limit this to a specific user as well. When I’m done writing this, I’ll do just that. Route 6 This route just shortens up the reply URL. I’m considering changing this to either /scott/my-first-post/reply or /reply/scott/my-first-post. Route 7 This cleans up replying to a comment. I could also change this to something like the proposed change to route 6, and give the comment a slug as well. Routes 8 – 11 These are convenience URLs for logged in users. Pretty self explanatory. Route 12 This is the default catch-all route that catches every other /controller/action/id style Rails URL that is not covered in the routes before it. As you can see, Routes are so sexy and easy that even while trying to explain my current routes, I can come up with ways to add or modify them. The additions to routes 6 and 7 will be very easy to do. Jump on the bandwagon. Get your beta gems today and start Routing. This article brought to you by the
Hiveminds Magazine - Staff. Contact us if you want to post an article or announcement anonymously Thoughtbox - So what did you think? |
Content Management Systems London Hotels
Web Developers Laptop Reviews
Content Management Systems Just Dial International Calls
Adobe Flex Windows Excel Training Courses
Joomla! excel courses in london
Silverlight Data Recovery
|
NewsletterGet updates on Hiveminds services, articles and downloads by signing up for the newsletter. |
Editor's choiceSome of the better articles, stories and tutorials found at Hiveminds. |
Find moreFind more of Hiveminds articles, stories, tutorials and user comments by searching. |
Picked linksHand picked websites and articles from around the web that provide quality reading. |