HW 4: Your first Rails app (Hartl, Chapter 2)
I expect that this assignment should take you about two hours.
Warning! This assignment relies on Cloud 9. Cloud 9 is in transition. Please use the traditional Cloud 9, if possible. I’ve included notes below to explain of the primary differences.
A note from Sam
git, please don’t use
git commit -a or
git add .. You
should pay attention to the individual files you’re working with. It takes
only a little while longer, it’s better practice, and, in the long term,
it saves you from big mistakes. (If you don’t know the alternative to
git commit -a, let me know.)
Your primary task
Do all of the steps and exercises in Chapter 2 of Michael Hartl’s The Rails Tutorial. You will then answer some questions on those steps. You may find it useful to read the questions in advance.
What to submit
Send me answers to the following questions in a message entitled “CSC 321.01 2018S, HW 4: Your first Rails app (Hartl, Chapter 2) (Name)”. Please replace Name with your name.
What is the URL of your Cloud 9 instance? (E.g.,
As you likely noted,
rails generate scaffoldcreates a lot of files. Explain the (likely) purpose of each of the following.
db/migrate/20180111111111_create_users.rb(you will have a slightly different name)
What files did
rails generate scaffoldmodify? What changes did it make to those files?
What changes would you have to make to the application to show the user id on the
Rails often relies on “convention over configuration”. There’s a subtle instance of that principle in section 2.3.3. What unstated information is implicit in the design of the relationship between users and microposts?
As Hartl notes, the toy application is not nearly robust enough. Consider, for example, the association of posts with users. As you may have noted, once we have the validation in place, Rails stops you from adding a post with an invalid user id. However, it is possible to end up with a post whose
user_iddoes not reference a valid user. How?
Hartl does not have us commit changes until we are ready to deploy to Heroku. What are some earlier steps in which a commit might be appropriate?
A student who was experimenting with this application added the following line to
app/views/microposts/index.html.erb. Explain what this code does.
<td><%= micropost.user ? micropost.user.name : "???" %></td>
Some notes on using the “traditional”
Don’t forget that your work is in the
workspacedirectory rather than the
Don’t forget to start your Rails server with
rails server -b $IP -p $PORT
In section 2.3.4, Hartl references
ApplicationController. You may find that your application is using