Class: MediaGallery::ImageScratchesController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- MediaGallery::ImageScratchesController
- Defined in:
- app/controllers/media_gallery/image_scratches_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /image_scratches.
-
#destroy ⇒ Object
DELETE /image_scratches/1.
-
#index ⇒ Object
GET /image_scratches.
Methods inherited from ApplicationController
#create_ability, #current_ability, #current_user
Instance Method Details
#create ⇒ Object
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); :create, @scratch @scratch.save! @scratch.image_version = ImageVersion.new(image: image_scratch_params[:image], ownable: @scratch); @scratch.save! end end |
#destroy ⇒ Object
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 |
#index ⇒ Object
GET /image_scratches
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 ( :read, @scratches[0]) unless @scratches.empty? end |