我遇到了同样的问题: Multi-step form in Rails 3 with Paperclip attachments
“TypeError in ...”“无法转储文件”
但是,我似乎无法解决答案中提到的解决方案:
unless @model.valid?
@model.image.clear
@model.image.queued_for_write.clear
end
我在哪里放上线?
这是我的控制器的代码:
def new
session[:member_params] ||= {}
@member = Member.new(session[:member_params])
@member.current_step = session[:member_step]
end
def create
session[:member_params].deep_merge!(params[:member]) if params[:member]
@member = Member.new(session[:member_params])
@member.current_step = session[:member_step]
if @member.valid?
if params[:back_button]
@member.previous_step
elsif @member.last_step?
@member.save if @member.all_valid?
else
@member.next_step
end
session[:member_step] = @member.current_step
end
if @member.new_record?
render "new"
else
session[:member_step] = session[:member_params] = nil
flash[:notice] = "Personal Data Sheet saved!"
redirect_to @member
end
end
我在宣布@member
之后尝试将它放在这里,但没有好处:
session[:member_params].deep_merge!(params[:member]) if params[:member]
@member = Member.new(session[:member_params])
unless @member.valid?
@member.image.clear
@member.image.queued_for_write.clear
end
P.S。 我想在这里提出问题: Multi-step form in Rails 3 with Paperclip attachments 但我不确定在同一问题/问题上发布后续问题是否可以。