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
This commit is contained in:
parent
d6a9e133d3
commit
d7784fa8a1
1 changed files with 4 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue