Class: PhotosController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/photos_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/photos_controller.rb', line 22

def create
newparams = coerce(params)
  @photo = Photo.new(newparams[:photo])
  if @photo.save
    flash[:notice] = "Successfully created photo."
    respond_to do |format|
      format.html { redirect_to @photo.album }
      format.json { render :json => { :result => 'success', :photo => photo_url(@photo) } }
    end
  else
    render :action => 'new'
  end
end

#destroyObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/photos_controller.rb', line 58

def destroy
  if request.post?
 		if params[:photo_ids]
		params[:photo_ids].each do |photo|
     	@photo = Photo.find photo
     	@photo.destroy
		end 
   	flash[:notice] = "Photos Successfully deleted!"
  	end
  	respond_to do |format|
   	if Photo.all.blank?
			format.html { redirect_to(albums_url) }
		else
   		format.html { redirect_to(:back) }
		end
  end
end
end

#editObject



36
37
38
39
40
41
42
43
# File 'app/controllers/photos_controller.rb', line 36

def edit
if params[:edit] == 'photo'
	render :layout => false
	@photo = Photo.find(params[:id])
else
	@photo = Photo.find(params[:id])
end
end

#indexObject



8
9
10
11
# File 'app/controllers/photos_controller.rb', line 8

def index
  @photos = Photo.page(params[:search], params[:page])
	@photo_albums = @photos.group_by { |photo| photo.album.title }
end

#newObject



18
19
20
# File 'app/controllers/photos_controller.rb', line 18

def new
  @photo = Photo.new
end

#showObject



13
14
15
16
# File 'app/controllers/photos_controller.rb', line 13

def show
  @photo = Photo.find(params[:id], :include => :album)
@total_uploads = Photo.find(:all, :conditions => { :album_id => @photo.album.id})
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/photos_controller.rb', line 45

def update
  @photo = Photo.find(params[:id])
  if @photo.update_attributes(params[:photo])
    flash[:notice] = "Successfully updated photo."
    respond_to do |format|
      format.html { redirect_to album_url(@photo.album)}
      format.js { render :json => { :result => 'success', :album => album_url(@photo.album) } }
    end
  else
    render :action => 'edit'
  end
end