-
Understand how you can take information from your database and display it to your users
-
Create a has_many relationship in your application
- Continue using the
sinatra_blog
you created during the last homework assignment. Add aposts
table to your application (remember: you will need to use migrations) and establish a has_many relationship between users and posts, whereusers can have many posts
. Theposts
table should have three fields: title, body and a foreign key. - Once you have established the has_many relationship at the database level, you will also need to communicate the relationship at the application level. After that is done, use irb and activerecord to add posts to users.
- In your application, add a new route
get '/users'
that will display a list of all of the users in your database - Next, create a another route
get '/users/:id
that will display the information for only one user. For example - by typinglocalhost:4567/users/3
in your address bar, you should be redirected to a page that only displays the information for the user in your database that has an id of 3. - On the detail page (from the step above) - display the name and email of the user. Also, display a list of the post titles they have
Hint: We went through these steps using the sinatra_todo application, so reference that application to guide your through this assignement
VERY IMPORTANT: If you haven't already done so; please ensure that your laptop is correctly set up for Rails development by following the setup instructions found on installrails.com. If this is not completed before next class, you will run into issues and you may fall behind.