Skip to content
Extraits de code Groupes Projets
photos_controller.rb 1,39 ko
Newer Older
Raphael's avatar
Raphael a validé
class PhotosController < ApplicationController
  before_filter :authenticate_user!

  respond_to :html
  respond_to :json, :only => :show
Raphael's avatar
Raphael a validé
  
  def create
    
    album = Album.find_by_id params[:album_id]

      @photo = current_user.post(:photo, params)
    rescue TypeError
      message = "Photo upload failed.  Are you sure an image was added?"
      respond_with :location => album, :error => message

    rescue CarrierWave::IntegrityError
      message = "Photo upload failed.  Are you sure that was an image?"
      respond_with :location => album, :error => message

      message = "Photo upload failed.  Are you sure that your seatbelt is fastened?"
      respond_with :location => album, :error => message
Raphael's avatar
Raphael a validé
  end
  
  def new
    @photo = Photo.new
    @album = current_user.album_by_id(params[:album_id])
Daniel Vincent Grippi's avatar
Daniel Vincent Grippi a validé
    render :partial => 'new_photo'
Raphael's avatar
Raphael a validé
  end
  
  def destroy
    @photo = Photo.find_by_id params[:id]
Raphael's avatar
Raphael a validé
    @photo.destroy
    respond_with :location => @photo.album
Raphael's avatar
Raphael a validé
  end
  
  def show
    @photo = Photo.find_by_id params[:id]
maxwell's avatar
maxwell a validé
    @album = @photo.album
Raphael's avatar
Raphael a validé
  end
    @photo = Photo.find_by_id params[:id]
    @photo = Photo.find_by_id params[:id]
    @photo.update_attributes params[:photo]

    respond_with @photo
Raphael's avatar
Raphael a validé
end