我正在实现一个多步表单 - 如#217 Multistep Forms - Railscasts所示- 并遇到了一个错误:
can't dump File
以下是new
和create
行动:
def new
session[:batch_params] ||= {}
@batch = current_user.batches.build
respond_to do |format|
format.html # new.html.erb
format.json { render json: @batch }
end
end
def create
session[:batch_params].deep_merge!(params[:batch]) if params[:batch]
@batch = current_user.batches.build(session[:batch_params])
if @uploaded
@batch.file = @uploaded
end
@batch.current_step = session[:batch_step]
if params[:back_button]
@batch.previous_step
elsif @batch.last_step?
@batch.file = session[:file]
@batch.save
else
@batch.next_step
end
session[:batch_step] = @batch.current_step
if @batch.new_record?
render 'new'
else
session[:batch_step] = session[:batch_params] = nil
flash[:notice] = "Batch was successfully created"
redirect_to @batch
end
end
问题是:文件需要在第一步更新,因为我需要读取它并获取要在第二步中使用的行数。所以我试图在会话中存储一个文件,并且由于无法对其进行序列化,所以我收到了这个错误。
如何避免这样做?我相信我应该在第一步上传文件,然后只需将其网址提供给以下步骤;这是对的吗?
我怎样才能做到这一点?