We will talk about Ratings, but focus on code for Artists and Songs only.
Did everyone create lots of objects?
Action View and Action Controller are the two major components of Action Pack. In Rails, web requests are handled by Action Pack, which splits the work into a controller part (performing the logic) and a view part (rendering a template). Typically, Action Controller will be concerned with communicating with the database and performing CRUD actions where necessary. Action View is then responsible for compiling the response.
After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output (action and view).
Let's work together to build the Artists, Songs, and Ratings controllers. Start with running the generate commands in the terminal:
$ rails generate controller Artists $ rails generate controller Songs $ rails generate controller Ratings
The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views.
Since ratings belong to songs, and songs belong to artists, we need nested routes.
Action View templates are written using embedded Ruby in tags mingled with HTML. To avoid cluttering the templates with boilerplate code, a number of helper classes provide common behavior for forms, dates, and strings. It's also easy to add new helpers to your application as it evolves.
Let's work together to build the Artist Index and Show views.
Build your own Song Show view
<h1><%= @song.title %></h1>
From the album: <%= @song.album %>.
Today, we built the controllers and views for our application, including forms to create new songs, as well as all the necessary routing.
App code available on Github.
Ensure that you have an account set up on Heroku.com.
Read the documentation for the Devise gem. We'll be using it next week.