I have a multi-step form inspired by this railcast that has 3 file upload images. However when I upload an image I receive an error can't dump File
.
From other questions in SO I understand that saving a file uploads in the session doesn't work so I need ot use something like this:
unless @post.valid?
@post.assets.first.attachment.clear
@post.assets.first.attachment.queued_for_write.clear
end
This however doesn't seem to work. Should I look through the three file uploads and clear them every time? How can I avoid this error?
Here is my create function:
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
My asset model
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