Skip to content
Extraits de code Groupes Projets
photos_controller.rb 1,3 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    class PhotosController < ApplicationController
    
      before_filter :authenticate_user!
    
    Raphael's avatar
    Raphael a validé
      
      def create
    
          @photo = current_user.post(:photo, params)
    
          if @photo.created_at
    
            flash[:notice] = "Successfully uploaded photo."
          else
            render :action => 'album#new'
          end
    
        rescue TypeError
          flash[:error] = "Photo upload failed. Are you sure an image was added?"
          redirect_to Album.first(:id => params[:photo][:album_id])
        rescue CarrierWave::IntegrityError || 
          flash[:error] = "Photo upload failed.  Are you sure that was an image?"
          redirect_to Album.first(:id => params[:photo][:album_id])
        end
    
    Raphael's avatar
    Raphael a validé
      end
      
      def new
        @photo = Photo.new
    
    Raphael's avatar
    Raphael a validé
        render :partial => "new_photo"
    
    Raphael's avatar
    Raphael a validé
      end
      
      def destroy
    
        @photo = Photo.first(:id => params[:id])
    
    Raphael's avatar
    Raphael a validé
        @photo.destroy
        flash[:notice] = "Successfully deleted photo."
    
        redirect_to @photo.album
    
    Raphael's avatar
    Raphael a validé
      end
      
      def show
    
        @photo = Photo.first(:id => params[:id])
    
    maxwell's avatar
    maxwell a validé
        @album = @photo.album
    
    Raphael's avatar
    Raphael a validé
      end
    
    
      def edit
        @photo= Photo.first(:id => params[:id])
        @album = @photo.album
      end
    
      def update
        @photo= Photo.first(:id => params[:id])
        if @photo.update_attributes(params[:photo])
          flash[:notice] = "Successfully updated photo."
          redirect_to @photo
        else
          render :action => 'edit'
        end
      end
    
    Raphael's avatar
    Raphael a validé
    end