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
31 lines
811 B
Ruby
31 lines
811 B
Ruby
class VideosController < ApplicationController
|
|
after_action :verify_authorized, except: %i[index]
|
|
before_action :set_cache_control_headers, only: %i[index]
|
|
|
|
def new
|
|
authorize :video
|
|
end
|
|
|
|
def index
|
|
@video_articles = Article.with_video
|
|
.includes([:user])
|
|
.select(:id, :video, :path, :title, :video_thumbnail_url, :user_id, :video_duration_in_seconds)
|
|
.order(hotness_score: :desc)
|
|
.page(params[:page].to_i).per(24)
|
|
|
|
set_surrogate_key_header "videos", Article.table_key, @video_articles.map(&:record_key)
|
|
end
|
|
|
|
def create
|
|
authorize :video
|
|
@article = ArticleWithVideoCreationService.new(article_params, current_user).create!
|
|
|
|
redirect_to "#{@article.path}/edit"
|
|
end
|
|
|
|
private
|
|
|
|
def article_params
|
|
params.require(:article).permit(:video)
|
|
end
|
|
end
|