Class: GalleriesController

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

Instance Method Summary collapse

Methods included from Pictrails::CachingMethods

included

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/galleries_controller.rb', line 5

def index
  @galleries = Gallery.paginate_by_status_and_parent_id true, nil,
    :include => 'pictures', 
    :page => params[:page],
    :per_page => this_webapp.galleries_pagination
  @tags = Picture.tag_counts

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @galleries }
  end
end

#showObject



18
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
54
55
56
57
58
59
# File 'app/controllers/galleries_controller.rb', line 18

def show
  @gallery = Gallery.find_by_permalink(params[:id]) 
  raise ActiveRecord::RecordNotFound if @gallery.nil?
  unless  @gallery.status
    redirect_to galleries_url
  else
    @breadcrumb = @gallery
    @tags = @gallery.tag_counts
    @sub_content = @gallery.children.paginate_by_status(true,
                                                        :order => 'created_at ASC, id ASC',
                                                        :page => params[:page],
                                                        :per_page => this_webapp.pictures_pagination,
                                                        :total_entries => (@gallery.nb_content))
    if @sub_content.size < this_webapp.pictures_pagination.to_i
      params[:page] = 1 if params[:page].nil?
      page = params[:page].to_i - (@sub_content.size / this_webapp.pictures_pagination.to_i)
      per_page = this_webapp.pictures_pagination.to_i - @sub_content.size
      if @sub_content.empty?
        @sub_content.replace(@sub_content + 
                             @gallery.pictures.paginate_by_status(true,
                                                                  :order => 'created_at ASC, id ASC',
                                                                  :page => (page),
                                                                  :per_page => per_page,
                                                                  :shift => @gallery.diff_paginate)) 
      else
        @sub_content.replace(@sub_content + 
                             @gallery.pictures.paginate_by_status(true,
                                                                  :order => 'created_at ASC, id ASC',
                                                                  :page => page,
                                                                  :per_page => per_page)) 
      end
    end

    respond_to do |format|
      format.html 
      format.xml  { render :xml => @gallery }
      format.atom
    end
  end
rescue ActiveRecord::RecordNotFound
  render :status => 404
end