Class: Admin::Reviews::PhotosController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/reviews/photos_controller.rb

Overview

typed: ignore frozen_string_literal: true

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
# File 'app/controllers/admin/reviews/photos_controller.rb', line 15

def create
  params.require(:review_photo).require(:photo).each do |photo|
    ReviewPhoto.create!({ review_id: review.id }.merge(photo: photo))
  end
  redirect_to admin_blogger_review_photos_path(@review)
end

#destroyObject



22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/admin/reviews/photos_controller.rb', line 22

def destroy
  photo = ReviewPhoto.find_by id: params.require(:id), review_id: review.id
  if photo.blank?
    redirect_back fallback_location: back_fallback_location, alert: 'Photo not found'
  end
  if photo.destroy
    redirect_to admin_blogger_review_photos_path(@review)
  else
    redirect_back fallback_location: back_fallback_location, alert: photo.errors.full_messages.to_sentence
  end
end

#indexObject



7
8
9
# File 'app/controllers/admin/reviews/photos_controller.rb', line 7

def index
  @photos = review.review_photos
end

#newObject



11
12
13
# File 'app/controllers/admin/reviews/photos_controller.rb', line 11

def new
  @photo = review.review_photos.build
end