1 class FollowsController < ApplicationController
6 before_action :authorize_web
7 before_action :set_locale
8 before_action :check_database_readable
12 before_action :check_database_writable
13 before_action :lookup_user
16 @already_follows = current_user.follows?(@user)
21 follow.follower = current_user
22 follow.following = @user
23 if current_user.follows?(@user)
24 flash[:warning] = t ".already_followed", :name => @user.display_name
25 elsif current_user.follows.where(:created_at => Time.now.utc - 1.hour..).count >= current_user.max_follows_per_hour
26 flash[:error] = t ".limit_exceeded"
28 flash[:notice] = t ".success", :name => @user.display_name
29 UserMailer.follow_notification(follow).deliver_later
31 follow.add_error(t(".failed", :name => @user.display_name))
34 referer = safe_referer(params[:referer]) if params[:referer]
36 redirect_to referer || user_path
40 if current_user.follows?(@user)
41 Follow.where(:follower => current_user, :following => @user).delete_all
42 flash[:notice] = t ".success", :name => @user.display_name
44 flash[:error] = t ".not_followed", :name => @user.display_name
47 referer = safe_referer(params[:referer]) if params[:referer]
49 redirect_to referer || user_path