]> git.openstreetmap.org Git - rails.git/commitdiff
Replace lookup_friend with lookup_user in FollowsController
authorAnton Khorev <tony29@yandex.ru>
Sat, 18 Jan 2025 16:35:30 +0000 (19:35 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 18 Jan 2025 16:35:30 +0000 (19:35 +0300)
app/controllers/follows_controller.rb
app/views/follows/show.html.erb

index 39d6191cd80445330b9ec56ec5d59b3cd43293b4..a8da933dff89d0a06360ebebb5191fdf8333db56 100644 (file)
@@ -10,25 +10,25 @@ class FollowsController < ApplicationController
   authorize_resource
 
   before_action :check_database_writable
-  before_action :lookup_friend
+  before_action :lookup_user
 
   def show
-    @already_follows = current_user.follows?(@friend)
+    @already_follows = current_user.follows?(@user)
   end
 
   def create
     follow = Follow.new
     follow.follower = current_user
-    follow.following = @friend
-    if current_user.follows?(@friend)
-      flash[:warning] = t ".already_followed", :name => @friend.display_name
+    follow.following = @user
+    if current_user.follows?(@user)
+      flash[:warning] = t ".already_followed", :name => @user.display_name
     elsif current_user.follows.where(:created_at => Time.now.utc - 1.hour..).count >= current_user.max_follows_per_hour
       flash[:error] = t ".limit_exceeded"
     elsif follow.save
-      flash[:notice] = t ".success", :name => @friend.display_name
+      flash[:notice] = t ".success", :name => @user.display_name
       UserMailer.follow_notification(follow).deliver_later
     else
-      follow.add_error(t(".failed", :name => @friend.display_name))
+      follow.add_error(t(".failed", :name => @user.display_name))
     end
 
     referer = safe_referer(params[:referer]) if params[:referer]
@@ -37,25 +37,15 @@ class FollowsController < ApplicationController
   end
 
   def destroy
-    if current_user.follows?(@friend)
-      Follow.where(:follower => current_user, :following => @friend).delete_all
-      flash[:notice] = t ".success", :name => @friend.display_name
+    if current_user.follows?(@user)
+      Follow.where(:follower => current_user, :following => @user).delete_all
+      flash[:notice] = t ".success", :name => @user.display_name
     else
-      flash[:error] = t ".not_followed", :name => @friend.display_name
+      flash[:error] = t ".not_followed", :name => @user.display_name
     end
 
     referer = safe_referer(params[:referer]) if params[:referer]
 
     redirect_to referer || user_path
   end
-
-  private
-
-  ##
-  # ensure that there is a "friend" instance variable
-  def lookup_friend
-    @friend = User.active.find_by!(:display_name => params[:display_name])
-  rescue ActiveRecord::RecordNotFound
-    render_unknown_user params[:display_name]
-  end
 end
index 3b82f4b5b4dea92a7fd96e75a0ec98d4825c8d47..18773627132dbd763a37b483f2749d37fb5c6428 100644 (file)
@@ -1,5 +1,5 @@
 <% content_for :heading do %>
-  <h1><%= t(@already_follows ? ".unfollow.heading" : ".follow.heading", :user => @friend.display_name) %></h1>
+  <h1><%= t(@already_follows ? ".unfollow.heading" : ".follow.heading", :user => @user.display_name) %></h1>
 <% end %>
 
 <%= bootstrap_form_tag :method => (@already_follows ? :delete : :post) do |f| %>