Sample following data: Adding following/follower relationships to the sample data

Run commands:
rake db:reset
rake db:populate <-- a task defined by us
rake test:prepare
A web interface for following users: Create routes for two separate pages, which list user's followed users & followers respectively. We will create two links like "50 following" & "77 followers" on user's profile page & home page, to these two pages.

Techniques:
We write in route.rb:
  resources :users do
    member do
      get :following, :followers
    end
  end

Which generates routes like:
        Prefix Verb   URI Pattern                    Controller#Action
following_user GET    /users/:id/following(.:format) users#following
followers_user GET    /users/:id/followers(.:format) users#followers

So we can GET url /users/1/following or /users/1/follower.
Note the named routes are 'following_user_path(user)' or 'following_user_url(user)'

What if we want 'member' on collection, works without the id? That will be:
  resources :users do
    collection do
      get :tigers
    end
  end
The URL will then be:
  /users/tigers

See http://guides.rubyonrails.org/routing.html for more.
Stats and a follow form: Add failing tests for the following/follower statistics (which are links as well) on the Home page
Stats and a follow form: Display following/follower stats on home page

A partial 'shared/stats' added

Note in the partial, we write:
<% @user ||= current_user %>

This is because the partial will be used in both home page & user's show page
In user's show page, @user is not nil; but in home page @user is nil
Stats and a follow form: Add styles to the following/follower stats on home page
Stats and a follow form: Add 3 partials for follow/unfollow form

Note in the follow form we have:

<%= form_for(current_user.relationships.build(followed_id: @user.id)) do |f| %>
  <div><%= f.hidden_field :followed_id %></div>
  <%= f.submit "Follow", class: "btn btn-large btn-primary" %>
<% end %>

In the unfollow form we have:

<%= form_for(current_user.relationships.find_by(followed_id: @user.id),
             html: { method: :delete }) do |f| %>
  <%= f.submit "Unfollow", class: "btn btn-large" %>
<% end %>

These two forms both use 'form_for' to manipulate a Relationship model object. (Remember user.relationships.build returns a Relationship object, while user.relationships.find_by also returns a Relationship object)
So, the former sends a POST request to /relationships to create a relationship, while the latter sends a DELETE request to /relationships/<id> to destroy a relationship.
Thus, we also need to define routes for Relationships resource:

resources :relationships, only: [:create, :destroy]

Results in:
        Prefix Verb   URI Pattern                    Controller#Action
 relationships POST   /relationships(.:format)       relationships#create
  relationship DELETE /relationships/:id(.:format)   relationships#destroy

Techniques:
Though in the 'follow' form we have nothing but one button "Follow", we still have to send the 'followed_id' to the RelationshipsController.
We accomplish this with the 'hidden_field' method

  <div><%= f.hidden_field :followed_id %></div>

Which produces HTML of the form

  <input id="relationship_followed_id"
   name="relationship[followed_id]"
   type="hidden" value="3" />

Note that the 'f.hidden_field' is a method similar with 'f.input' or 'f.label'.
And the symbol ':followed_id' tells Rails two things:
1. The value of this hidden input field is 'relationship[:followed_id]', where the relationship object was 'build' one line above:
  <%= form_for(current_user.relationships.build(followed_id: @user.id)) do |f| %>
2. When the form is submitted, there will be 'params[:relationship][:followed_id]' containing the value this field. And because the field is hidden, it's still the intial value.
Stats and a follow form: Add the stats form & follow/unfollow form to the user show page (i.e. Profile page).

Note that 'follow/unfollow' buttons don't work because we have not implement the RelationshipsController#create and #destroy methods.
Following and followers pages: Add failing tests for the authorization of the following and followers pages

If non-signed-in user visits these urls, he should be redirect to the sign in page.
Following and followers pages: Add more failing tests for the separated followed_users and followers pages
Following and followers pages: Get the tests green by adding the UsersController#following and #followers actions

Note that in the controller we call

render 'show_follow'

This is not a partial, but an explicit call to render. In this case rendering a view called 'show_follow', not '_show_follow'.