Our apps are nothing more than a collection of URLs that we decide to allow users to access:
mydomain.com/products
mydomain.com/photos/193
mydomain.com/signin
So remember: everything always starts with a route between a URL we want to support and a Ruby method that will be responsible for generating a response to the user's browser.
In order to support a URL in your app such as http://localhost:3000/signin
, there are a lot of dots to connect!
- First we need a route for the URL we want to support (green).
- The route will specify the Ruby class and the method that will be responsible for rendering a response. We call the class a controller and the method an action.
- Whatever name you choose in the route for the controller determines the things in red:
- the filename in the app/controllers folder (must be snake_case)
- the class name in the file (must be CamelCase)
- the folder name in the app/views folder
- Whatever name you choose in the route for the action determines the things in blue, and usually also the things in pink, since by convention we name them the same thing (but we don't have to):
- the name of the method we define within the controller class
- the name of the view template that we render in the action
- the name of the .html.erb file within the app/views/ folder