]> git.openstreetmap.org Git - rails.git/blob - app/controllers/follows_controller.rb
Replace lookup_friend with lookup_user in FollowsController
[rails.git] / app / controllers / follows_controller.rb
1 class FollowsController < ApplicationController
2   include UserMethods
3
4   layout "site"
5
6   before_action :authorize_web
7   before_action :set_locale
8   before_action :check_database_readable
9
10   authorize_resource
11
12   before_action :check_database_writable
13   before_action :lookup_user
14
15   def show
16     @already_follows = current_user.follows?(@user)
17   end
18
19   def create
20     follow = Follow.new
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"
27     elsif follow.save
28       flash[:notice] = t ".success", :name => @user.display_name
29       UserMailer.follow_notification(follow).deliver_later
30     else
31       follow.add_error(t(".failed", :name => @user.display_name))
32     end
33
34     referer = safe_referer(params[:referer]) if params[:referer]
35
36     redirect_to referer || user_path
37   end
38
39   def destroy
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
43     else
44       flash[:error] = t ".not_followed", :name => @user.display_name
45     end
46
47     referer = safe_referer(params[:referer]) if params[:referer]
48
49     redirect_to referer || user_path
50   end
51 end