All pastes #44947 Raw Edit

Something

public text v1 · immutable
#44947 ·published 2006-03-08 20:22 UTC
rendered paste body
  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