def create begin @fanartfile = @params['fanart_image'] @extension = File.extname(@fanartfile.original_filename) if (!((@extension == "png") || (@extension == "jpg") || (@extension == "gif") || (@extension == "swf"))) flash[:notice] = "You can't upload non-image files!" redirect_to(:action => 'new') end @fanart = Fanart.new(params[:fanart]) @fanart.format = @extension if @fanart.save File.open("#{RAILS_ROOT}/public/fanarts/#{@fanart.id}.#{@extension}", "wb") do |f| f.write(@fanartfile.read) end flash[:notice] = 'Fanart entry was successfully added.' redirect_to :action => 'list' else render :action => 'new' end rescue :flash[:notice] = 'Could not save the fanart!'; redirect_to :action => 'new' end end