Unfollowing Users

A few readers have also asked me to add an Unfollow button for the sample social network in Rails Crash Course. Here’s how I made that happen:

I created a new branch called unfollow-user and added the Unfollow button.

Here are the steps I followed:

  1. Update config/routes.rb to include a route for unfollow_user. Since this removes a row from the database, I used the DELETE HTTP verb.
  2. Add an unfollow! method to app/models/user.rb, similar to the follow! method.
  3. Add an unfollow action to app/controllers/users_controller.rb, similar to the follow action.
  4. Add a Unfollow button to the view at app/views/users/show.html.erb. I also added some logic to show the correct button.

The changes are in this commit: 29fa67a

Hope this helps!

Destroying Comments

A reader asked if I could add the destroy action to CommentsController for the sample blog in Rails Crash Course. The changes are summarized below.

I created a new branch called comments-destroy and then added the destroy action.

Here are the steps I followed:

  1. Update config/routes.rb to include a route for comments destroy
  2. Add a destroy method to app/controllers/comments_controller.rb
  3. Add a Destroy link to the comment partial at app/views/comments/_comment.html.erb

The changes are in this commit: f410496

Note this is the same as Exercise 3 at the end of Chapter 5. The answers for all exercises are in the back of the book.

Hope this helps!