Class: Ishapi::GalleriesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#exception, #home, #long_term_token, #vote

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
# File 'app/controllers/ishapi/galleries_controller.rb', line 9

def index
  @galleries = Gallery.all.published
  authorize! :index, Gallery
  if params[:domain]
    @site = Site.find_by( :domain => params[:domain], :lang => 'en' )
    @galleries = @galleries.where( :site => @site )
  end
  @galleries = @galleries.page( params[:galleries_page] ).per( 10 )
end

#showObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/ishapi/galleries_controller.rb', line 19

def show
  @gallery   = ::Gallery.unscoped.where( slug: params[:slug] ).first
  @gallery ||= ::Gallery.unscoped.where( id: params[:slug]   ).first
  authorize! :show, @gallery

  @photos = @gallery.photos.order_by( ordering: :asc )
  respond_to do |format|
    format.json do

      if @gallery.is_premium
        if @current_user&.profile&.has_premium_purchase( @gallery )
          render 'show_premium_unlocked'
        else
          render 'show_premium_locked'
        end
      else
        render 'show'
      end

    end
    format.html do

      if @gallery.is_premium
        if @current_user&.profile&.has_premium_purchase( @gallery )
          render 'show_premium_unlocked'
        else
          render 'show_premium_locked'
        end
      else
        render 'show'
      end

    end
  end
end