我有一个多步骤的形式灵感来自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