blob: e7368c3f9aef92b58bb4e1a3dfdf5a161725345a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# frozen_string_literal: true
class Posts::ThumbnailsController < ApplicationController
def update
@post = Post.find(params[:post_id])
authorize! :update_thumbnail, @post
if params[:thumbnail_id].present?
@thumbnail = Post.find_by(id: params[:thumbnail_id])
unless @thumbnail
render partial: 'posts/thumbnail_container_inner', locals: { has_thumbnail: false, can_edit_thumbnail: true, error: 'Thumbnail not found!' }, layout: false
return
end
authorize! :read, @thumbnail
else
@thumbnail = nil
end
@post.update(thumbnail: @thumbnail, updated_at: Time.zone.now)
render partial: 'posts/thumbnail_container_inner', locals: { has_thumbnail: @thumbnail.present?, can_edit_thumbnail: true, no_hide: true }, layout: false
end
end
|