Class: MediaGallery::GalleriesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#create_ability, #current_ability, #current_user

Instance Method Details

#createObject

POST /galleries



16
17
18
19
20
21
22
23
24
# File 'app/controllers/media_gallery/galleries_controller.rb', line 16

def create
  @gallery = Gallery.new(
    name: gallery_params[:name],
    ownable: current_user,
    description: gallery_params[:description]
  )
  authorize! :create, @gallery
  @gallery.save!
end

#destroyObject

DELETE /galleries/1



38
39
40
# File 'app/controllers/media_gallery/galleries_controller.rb', line 38

def destroy
  @gallery.destroy
end

#indexObject

GET /galleries

Raises:

  • (CanCan::AccessDenied)


9
10
11
12
13
# File 'app/controllers/media_gallery/galleries_controller.rb', line 9

def index
  raise CanCan::AccessDenied.new unless current_user
  @galleries = Gallery.where(ownable: current_user).order(name: :asc)
  authorize! :read, @galleries[0] if @galleries.length > 0
end

#showObject

GET /galleries/1



27
28
29
# File 'app/controllers/media_gallery/galleries_controller.rb', line 27

def show
  authorize! :read, @gallery
end

#updateObject

PATCH/PUT /galleries/1



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

def update
  authorize! :update, @gallery
  @gallery.update_attributes!(gallery_params)
end