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:
- Update
config/routes.rb
to include a route forunfollow_user
. Since this removes a row from the database, I used theDELETE
HTTP verb. - Add an
unfollow!
method toapp/models/user.rb
, similar to thefollow!
method. - Add an
unfollow
action toapp/controllers/users_controller.rb
, similar to thefollow
action. - 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!