You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Model: Responsible for handling data logic (eg. database queries)
View: Responsible for the UI (User Interface)
Controller: Ties the model and view together, talks to both and shares data between them
Rails also uses a router (routes.rb) sitting between the user requests and the controllers that respond to those requests
Rails Libraries
Rails is a framework made up of a collection of libraries
Active Record
An Object Relational Mapper (ORM)
Allows you to query and modify the application data in an intuitive way
Action View
Handles template lookup and rendering
Provides helpers for building forms and other UI elements
Action Controller
Controller library
Controller's make sense of the request and decide what should be returned to the client
Action Dispatch
The Rails router
Handles incoming requests and forwards them to the correct controller
Action Cable
Websockets for Rails
Nested Routes
We define the nesting in our routes. In routes.rb:
resources:authorsdoresources:booksend
Will generate:
author_books GET /authors/:author_id/books(.:format) books#index
POST /authors/:author_id/books(.:format) books#create
new_author_book GET /authors/:author_id/books/new(.:format) books#new
edit_author_book GET /authors/:author_id/books/:id/edit(.:format) books#edit
author_book GET /authors/:author_id/books/:id(.:format) books#show
PATCH /authors/:author_id/books/:id(.:format) books#update
PUT /authors/:author_id/books/:id(.:format) books#update
DELETE /authors/:author_id/books/:id(.:format)
Notice that these routes will be affected by the books Controller. All the logic will go there to work with these nested routes.
There are some nice helpful path helpers that get generated by this nested resource stuff. If you look at rake routes, you'll see the prefixes for these under PREFIX. For example, the path /authors/5/books could be generated by calling author_books(@author).