Rails Routing from the Outside In - Ruby on Rails Guides - 0 views
-
Resource routing allows you to quickly declare all of the common routes for a given resourceful controller.
-
Rails would dispatch that request to the destroy method on the photos controller with { id: '17' } in params.
- ...86 more annotations...
-
resource :photo and resources :photos creates both singular and plural routes that map to the same controller (PhotosController).
-
One way to avoid deep nesting (as recommended above) is to generate the collection actions scoped under the parent, so as to get a sense of the hierarchy, but to not nest the member actions.
-
You can leave out the :on option, this will create the same member route except that the resource id value will be available in params[:photo_id] instead of params[:id].
-
Routing Concerns allows you to declare common routes that can be reused inside other resources and routes
-
This will recognize /photos/1/preview with GET, and route to the preview action of PhotosController, with the resource id value passed in params[:id]. It will also create the preview_photo_url and preview_photo_path helpers.
-
This will enable Rails to recognize paths such as /photos/search with GET, and route to the search action of PhotosController. It will also create the search_photos_url and search_photos_path route helpers.
-
When you set up a regular route, you supply a series of symbols that Rails maps to parts of an incoming HTTP request.
-
This route will also route the incoming request of /photos to PhotosController#index, since :action and :id are
-
Inside the show action of UsersController, params[:username] will contain the username for the user.
-
'GET' in Rails won't check for CSRF token. You should never write to the database from 'GET' requests
-
-
-
This will provide you with URLs such as /bob/articles/1 and will allow you to reference the username part of the path as params[:username] in controllers, helpers and views
-
generate only the routes that you actually need can cut down on memory use and speed up the routing process.