thoughtbot/paperclip — Issue #642: Could not upload file and got original/missing.png
Author: kiinoo
Created: 2011-11-06 04:07:00+00:00
State: open

I'm going to upload an .xls file and import data from it, so I created a model like this:

class TaskImport < ActiveRecord::Base
has_attached_file :xls
end

when I browse a file (new a model of TaskImport) and submit (save the instance of TaskImport), I couldn't get TaskImport#xls.path which is empth, and TaskImport#xls is '/xls/original/missing.png'

then I tried to upload an image file, still got the same result.

The Controller code is:

class TaskImportsController < ApplicationController
#before_filter :login_required #protect controller from anonymous users
def new
@import = TaskImport.new
end

def create
@import = TaskImport.new(params[:import])

respond_to do |format|
if @import.save!
logger.debug "import #{@import.id} is saved!"
if @import.xls.nil?
logger.debug "Import[#{@import.id}].xls is nil!"
else
logger.debug "Import[#{@import.id}].xls is #{@import.xls}"
logger.debug "Import[#{@import.id}].xls.path is #{@import.xls.path}"
end
flash[:notice] = 'XLS data was successfully imported.'
format.html { redirect_to(@import) }
else
logger.debug "import #{@import.id} is NOT saved!"
flash[:error] = 'XLS data import failed.'
format.html { render :action => "new" }
end
end
end

def show
@import = TaskImport.find(params[:id])
end

Log is:
Started POST "/task_imports" for 127.0.0.1 at 2011-11-06 12:04:50 +0800
Processing by TaskImportsController#create as HTML
Parameters: {"utf8"=>"âœ“", "authenticity_token"=>"wqysK+jxYqIXZ5eE9e1HLuF/ILPu8rCw4f4FmPzJ7WA=", "task_import"=>{"xls"=>#>}, "commit"=>"Import"}
[1m[35mAREL (33.0ms)[0m INSERT INTO "task_imports" ("datatype", "processed", "xls_file_name", "xls_content_type", "xls_file_size", "created_at", "updated_at") VALUES (NULL, 0, NULL, NULL, NULL, '2011-11-06 04:04:50.369775', '2011-11-06 04:04:50.369775')
[paperclip] Saving attachments.
import 13 is saved!
Import[13].xls is /xls/original/missing.png
Import[13].xls.path is
Redirected to http://localhost:3000/task_imports/13
Completed 302 Found in 66ms