Guide Targets:
- How to interpret the code in
config/routes.rb
?-
http-verb + url
to match specified controller and action.
-
- How to construct routes using resourceful or match way?
- use
resourceful
style routes is recommend in Rails. - resources, single resource, nested resources, namespace, etc.
- use
- How to declare routes parameters which passed onto controller action?
- params are from url, post body and routing.
- How to auto create path and urls using route helpers?
- auto generate
_path
and_url
helpers.
- auto generate
- Advanced Techniques: constrains and mounting Rack endpoints.
My Notes
Helpers
- play in console with
app
app.magazine_ad_path(magazine, ad)
app.magazine_ad_url(magazine, ad)
app.url_for [magazine, ad] # call _url
app.root_path
Resourceful Routes
resources :photos
resource :profile
resources :photos, :books
Options
-
as
specify routes name -
path
specify routes url path -
module
specify controller module -
namespace
both change in name, path and module -
shallow
for nested resource, only nestedindex, new, create