From 082274d0d727c69233f232bcff23966c37b82af2 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 23 Jul 2010 11:59:04 -0700 Subject: [PATCH] RS IZ a nicer fail(notice) on wrong file format on upload --- app/controllers/photos_controller.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 5d2eeb868..546db0a74 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -2,14 +2,23 @@ class PhotosController < ApplicationController before_filter :authenticate_user! def create - @photo = Photo.instantiate(params[:photo]) - @photo.person = current_user + begin + @photo = Photo.instantiate(params[:photo]) + @photo.person = current_user - if @photo.save - flash[:notice] = "Successfully uploaded photo." - redirect_to @photo.album - else - render :action => 'album#new' + + + + if @photo.save + flash[:notice] = "Successfully uploaded photo." + redirect_to @photo.album + else + render :action => 'album#new' + end + + rescue + flash[:error] = "Photo upload failed. Are you sure that was an image?" + redirect_to Album.first(:id => params[:photo][:album_id]) end end