我有一個多步驟的形式靈感來自railcast有3個文件上傳圖像。但是,當我上傳圖像時,我收到錯誤can't dump File
。回形針和文件上傳問題
在其他問題使我明白,在會話保存文件上傳不工作,所以我需要OT使用這樣的事情:
unless @post.valid?
@post.assets.first.attachment.clear
@post.assets.first.attachment.queued_for_write.clear
end
然而,這似乎並沒有工作。我應該通過三個文件上傳並每次清除它們嗎?我怎樣才能避免這個錯誤?
這裏是我的創造功能:
session[:post_params].deep_merge!(params[:post]) if params[:post]
session[:duration] = params[:post_duration] if params[:post_duration]
@post = Post.new(session[:post_params])
@post.current_step = session[:post_step]
unless @post.valid?
logger.info("attachment " + @post.assets.first.attachment.inspect)
@post.assets.first.attachment.clear
@post.assets.first.attachment.queued_for_write.clear
end
if @post.valid?
if params[:back_button]
@post.previous_step
elsif @post.last_step?
if @post.all_valid?
...
session[:post_step] = session[:post_params] = nil
redirect_to @post and return
end
else
@post.next_step
end
session[:post_step] = @post.current_step
end
if @post.new_record?
render "new"
end
end
我的資產模型
class Asset < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :post
attr_accessible :attachment
has_attached_file :attachment, :styles => { :medium => "600x600>", :small => "200x200>", :thumb => "100x100>" },
:default_url => "no_image_:style.jpg"
end
我對此沒有太多的經驗,所以你可以從這個[StackOverflow post]獲得一些見解(http://stackoverflow.com/questions/5876714/multi-step-form-in -rails-3-with-paperclip-attachments/8079113#8079113) –
@RichPeck這確實是我發現的建議,用於清除圖像對象 – Ayrad
它可以幫助http://stackoverflow.com/questions/7079999/paperclipnotidentifiedbyimagemagickerror-image -is-not-recognized-the-ident/16933264#16933264 – Nithin