Path routes and helpers are automatically created when a resource is declared in the config/routes.rb file. For example, if the resource name is movies, this statement creates the routes:
map.resources :movies
Generating a scaffold with a Movie model (i.e. "rails generate scaffold Movie title:string ..."), automatically decares the movies resource in the routes.rb file. The table below shows the various movie-based names for the different components. The bottom row shows an example consisting of two words. Generally, class names (including the Model class and the Controller class) are camel-cased (e.g. RestaurantReviews) while all other multi-word names are connected by underscores (restaurant_reviews), including pathnames, filenames and database tables.
Resource name | Database table name | Model name | Controller name | View folder name |
---|---|---|---|---|
movies | movies | Movie | movies controller | movies |
people | people | Person | people controller | people |
restaurant_reviews | restaurant_reviews | RestaurantReview | restaurant_reviews controller | restaurant_reviews |
This table shows the routes and helpers that are created by clearing movies as a resource.
Operation | CRUD term | View helper for creating request | HTTP term | Resulting path | Controller Method |
---|---|---|---|---|---|
Get list of resource movies | Read | link_to "Movies", movies_path | GET | /movies | index |
Get a specific movie | Read | link_to "Movie", movie_path(@movie) OR link_to "Movie", @movie |
GET | /movies/1 | show |
Get form for creating new movie | Read | link_to "Create New Movie", new_movie_path | GET | /movies/new | new |
Create new movie | Create | form_for(@movie) | POST | /movies | create |
Get completed form for modifying an existing movie | Read | link_to "Update Movie", edit_movie_path(@movie) | GET | /movies/1/edit | edit |
Update existing movie | Update | form_for(@movie) | PUT (HTML form uses POST) | /movies/1 | update |
Delete existing movie | Destroy | link_to 'Destroy', @movie, :confirm => 'Are you sure?', :method => :delete | DELETE (HTML link creates POST form) | /movies/1 | destroy |
For the references to @movie
, it is assumed that this
references a movie object in the controller.