Class: MediaGallery::ImageScratchesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/media_gallery/image_scratches_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#create_ability, #current_ability, #current_user

Instance Method Details

#createObject

POST /image_scratches



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/media_gallery/image_scratches_controller.rb', line 15

def create
  ImageScratch.where(ownable: current_user).destroy_all

  # The persistence code that follows is suboptimal.  I'm a bit tired
  # right now.  Don't see it. Needs to be fixed.  Issue should be raised.
  # TODO Raise issue here.
  ActiveRecord::Base.transaction do
    @scratch = ImageScratch.new(ownable: current_user);
    authorize! :create, @scratch
    @scratch.save!
    @scratch.image_version = ImageVersion.new(image: image_scratch_params[:image], ownable: @scratch);
    @scratch.save!
  end

end

#destroyObject

DELETE /image_scratches/1



32
33
34
# File 'app/controllers/media_gallery/image_scratches_controller.rb', line 32

def destroy
  ImageScratch.destroy_all(ownable: current_user)
end

#indexObject

GET /image_scratches

Raises:

  • (CanCan::AccessDenied)


8
9
10
11
12
# File 'app/controllers/media_gallery/image_scratches_controller.rb', line 8

def index
  raise CanCan::AccessDenied.new unless current_user
  @scratches = ImageScratch.where(ownable: current_user).all
  (authorize! :read, @scratches[0]) unless @scratches.empty?
end