Class: Admin::GalleriesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/galleries_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /galleries POST /galleries.xml



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/admin/galleries_controller.rb', line 40

def create
  @gallery = Gallery.new(params[:gallery])

  respond_to do |format|
    if @gallery.save
      flash[:notice] = 'Gallery was successfully created.'
      format.html { redirect_to(admin_galleries_url) }
      format.xml  { render :xml => @gallery, :status => :created, :location => @gallery }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @gallery.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /galleries/1 DELETE /galleries/1.xml



74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/admin/galleries_controller.rb', line 74

def destroy
  @gallery = Gallery.find_by_permalink(params[:id])
  @gallery.destroy
  flash[:notice] = "The gallery #{@gallery.name} is deleted"

  respond_to do |format|
    format.html { redirect_to(admin_galleries_url) }
    format.xml  { head :ok }
  end
end

#editObject

GET /galleries/#permalink/edit

Raises:

  • (ActiveRecord::RecordNotFound)


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

def edit
  @gallery = Gallery.find_by_permalink(params[:id])
  raise ActiveRecord::RecordNotFound if @gallery.nil?
  @pictures = @gallery.pictures.paginate(:page => params[:page], :per_page => 20)
end

#follow_importObject

See the following of mass_upload



103
104
105
106
107
108
109
# File 'app/controllers/admin/galleries_controller.rb', line 103

def follow_import
  #@imports is affect in before_filter
  respond_to do |format|
    format.html{redirect_to :action => 'index' if @imports.empty?}
    format.js{render :layout => false}
  end
end

#indexObject



5
6
7
8
# File 'app/controllers/admin/galleries_controller.rb', line 5

def index
  @galleries = Gallery.find :all, :include => 'pictures'
  @page_title = 'List of Gallery'
end

#mass_uploadObject

Method to add mass upload with only one params the params define the directory where all picture are



91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/admin/galleries_controller.rb', line 91

def mass_upload
  if Gallery.create_from_directory params[:directory]
    redirect_to :action => 'follow_import'
  else
    flash[:notice] = 'the directory is not a directory'
    render :action => 'new'
  end
rescue ActiveRecord::RecordInvalid
  render :action => 'new'
end

#newObject



21
22
23
24
25
26
27
28
29
# File 'app/controllers/admin/galleries_controller.rb', line 21

def new
  @gallery = Gallery.new
  # By default the status is online
  @gallery.status = true
  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @gallery }
  end
end

#new_by_mass_uploadObject

View the form to create gallery by mass_upload



86
87
# File 'app/controllers/admin/galleries_controller.rb', line 86

def new_by_mass_upload
end

#showObject

See a gallery in Admin like a User



11
12
13
14
15
16
17
18
19
# File 'app/controllers/admin/galleries_controller.rb', line 11

def show
  @gallery = Gallery.find_by_permalink params[:id]
  unless @gallery.nil?
    @pictures = Picture.paginate_by_gallery_id @gallery.id, :page => params[:page],
      :per_page => 12
  else
    render :status => 404
  end
end

#updateObject

PUT /galleries/1 PUT /galleries/1.xml



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/admin/galleries_controller.rb', line 57

def update
  @gallery = Gallery.find_by_permalink(params[:id])

  respond_to do |format|
    if @gallery.update_attributes(params[:gallery])
      flash[:notice] = 'Gallery was successfully updated.'
      format.html { redirect_to admin_galleries_url }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @gallery.errors, :status => :unprocessable_entity }
    end
  end
end