Class: Admin::PicturesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

Create a picture in a Gallery



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/admin/pictures_controller.rb', line 51

def create
  @picture = Picture.new(params[:picture])
  
  respond_to do |format|
    if @picture.save
      flash[:notice] = 'Picture was successfully created.'
      format.html { redirect_to(admin_gallery_picture_url(params[:gallery_id], @picture)) }
      format.xml  { render :xml => @picture, :status => :created, :location => @picture }
    else
      define_gallery
      format.html { render :action => "new" }
      format.xml  { render :xml => @picture.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

Destroy the picture of a gallery



68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/admin/pictures_controller.rb', line 68

def destroy
  @picture = Picture.find_by_permalink(params[:id])
  @picture.destroy
  flash[:notice] = "Picture #{@picture.title} is deleted"

  respond_to do |format|
    format.html { redirect_to(edit_admin_gallery_url(params[:gallery_id])) }
    format.xml  { head :ok }
  end
end

#editObject

View the form to edit the picture



17
18
19
20
# File 'app/controllers/admin/pictures_controller.rb', line 17

def edit
  @picture = Picture.find_by_permalink params[:id]
  render :status => 404 if @picture.nil?
end

#indexObject

See all pictures



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

def index
  @pictures = Picture.paginate :page => params[:page], :per_page => 10
end

#newObject

View a form to add a new picture in a gallery



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/admin/pictures_controller.rb', line 23

def new
  @picture = Picture.new
  @picture.status = true
  @picture.gallery = Gallery.find_by_permalink params[:gallery_id]

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

#showObject

View the Picture when your are logged



11
12
13
14
# File 'app/controllers/admin/pictures_controller.rb', line 11

def show
  @picture = Picture.find_by_permalink params[:id]
  render :status => 404 if @picture.nil?
end

#updateObject

Update the Picture



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin/pictures_controller.rb', line 35

def update
  @picture = Picture.find_by_permalink(params[:id])
  @picture.title = params[:picture][:title]
  @picture.description = params[:picture][:description]
  @picture.status = params[:picture][:status]
  @picture.tag_list = params[:picture][:tag_list]
  if @picture.save
    flash[:notice] = 'Picture Updated'
    redirect_to admin_gallery_picture_url(@picture.gallery, @picture)
  else
    define_gallery
    render :action => 'edit'
  end
end