From 8ff017fc5b20034adb595ddcb36ede8663e3d147 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 5 Apr 2025 12:40:08 +0200 Subject: [PATCH] Only one invocation of this, not carrying the worth of its indirection Generally I am wary of including global state checks in the belly of models. It is one thing to do it as a default parameter, but I think it is too far to do it inside an actual method. --- app/controllers/comments_controller.rb | 2 +- app/models/user.rb | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index c0a9c9d34..d8b0231ac 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -38,6 +38,6 @@ class CommentsController < ApplicationController end def require_own_comment - head :forbidden unless @comment.creator.current? + head :forbidden unless Current.user == @comment.creator end end diff --git a/app/models/user.rb b/app/models/user.rb index e16518bee..5661afe8e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -32,10 +32,6 @@ class User < ApplicationRecord end end - def current? - Current.user == self - end - private def deactived_email_address email_address.sub(/@/, "-deactivated-#{SecureRandom.uuid}@")