Guide Targets:
- How to interpret the code in
config/routes.rb?-
http-verb + urlto match specified controller and action.
-
- How to construct routes using resourceful or match way?
- use
resourcefulstyle 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
_pathand_urlhelpers.
- 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 _urlapp.root_path
Resourceful Routes
resources :photosresource :profileresources :photos, :books
Options
-
asspecify routes name -
pathspecify routes url path -
modulespecify controller module -
namespaceboth change in name, path and module -
shallowfor nested resource, only nestedindex, new, create