Class: Admin::ReddePhotosController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/admin/redde_photos_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/admin/redde_photos_controller.rb', line 10

def create
  if photo_params[:imageable_id].present?
    parent = photo_params[:imageable_type].constantize.find(photo_params[:imageable_id])
    @photo = parent.photos.build(photo_params)
  else
    @photo = Redde::Photo.new(photo_params)
  end
  if @photo.save
    render(partial: 'photo', object: @photo)
  else
    render nothing: true, status: 422
  end
end

#destroyObject



24
25
26
27
28
# File 'app/controllers/admin/redde_photos_controller.rb', line 24

def destroy
  @photo = Redde::Photo.find(params[:id])
  @photo.destroy
  render 'admin/redde_photos/destroy'
end

#sortObject



2
3
4
5
6
7
8
# File 'app/controllers/admin/redde_photos_controller.rb', line 2

def sort
  params[:photo].each_with_index do |id, idx|
    p = Redde::Photo.find(id)
    p.update(position: idx)
  end
  render nothing: true
end