From d7784fa8a1249a9faf13660053b3243e0167b547 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Fri, 4 Mar 2022 11:08:53 -0500 Subject: [PATCH] Removing before_action in favor of explicity call (#16777) While in essence an idempotent change the purpose of this PR is to also favor explicit method calls over callbacks. Note, we don't have an associated model (e.g. Video) and instead rely on `:video` which Pundit converts to VideoPolicy. From my experience in rails it can become challenging to mentally parse the various before/after action paired with the only and except. As well as considering the timing of what happens when. Further this commit helps provide a record of "work" towards an issue. Closes forem/forem#16729 Reverses forem/forem#3806 --- app/controllers/videos_controller.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/videos_controller.rb b/app/controllers/videos_controller.rb index a56060262..31eaa1ced 100644 --- a/app/controllers/videos_controller.rb +++ b/app/controllers/videos_controller.rb @@ -1,9 +1,10 @@ class VideosController < ApplicationController after_action :verify_authorized, except: %i[index] before_action :set_cache_control_headers, only: %i[index] - before_action :authorize_video, only: %i[new create] - def new; end + def new + authorize :video + end def index @video_articles = Article.with_video @@ -16,6 +17,7 @@ class VideosController < ApplicationController end def create + authorize :video @article = ArticleWithVideoCreationService.new(article_params, current_user).create! redirect_to "#{@article.path}/edit" @@ -23,10 +25,6 @@ class VideosController < ApplicationController private - def authorize_video - authorize :video - end - def article_params params.require(:article).permit(:video) end