Relearning routes in Rails
-
Upload
juliana-lucena -
Category
Technology
-
view
597 -
download
2
Transcript of Relearning routes in Rails
Relearning routes in Rails
Routes in Rails 3
Juliana M. de Lucena@julianalucenaa
(Yes, it has two ‘a’)
“I love URLs. I dream about them at night. I think about them before I think about anything else.”
Adrian Holovaty, co-creator of DjangoFrom Webstock 2009
Our Path
• Good perceptions• Block declaration• Let’s see some routes
– Root– Resource– Default– Using constraints– Redirect– Namespace on route– Translating
• Let’s MAKE some routes
Let’s see some routing
• Resource route
– Nested resources
Old one
New one
Clean
“Resources should never be nested more than 1 level deep.” Rails Guides
Let’s see some routing
• Default route
Old one
New one
And you can name it like below
It generates show_tag_type_path
Let’s MAKE some routing
• Some advises
– In a DOJO way
– We are interest just on routes, forget about view, models and controllers things
– Do not be scared with specification, it will be very simple
Control your anxiety, it is on next page
Let’s MAKE some routing
• Exists a library– That has many books, employees and students
• A book– Can be created, edited, updated, deleted by any
employee
– Can be seen, borrowed and returned by everyone
– Is identified by a five characters code
• All employees– Can access some library private informations through
a special URL that begins with ‘admin’
Post method
Let’s MAKE some routing
• The library changed the name:
– When somebody access /my_old_library should redirect to /my_new_library
• With ‘/library/branchs’ we can see all libraries physical addresses (static page)
• Do not forget the root path
• All routes should be translated to portuguese
References
• Routing in Rails 3 - #203 Railscasts episode
• Ruby on Rails guides and 2.3.8 version
• http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/
• routes.rb itself