我尝试将变量保存在一个动作中,以便从我控制器中的另一个动作调用它。我使用session来保存它,如下所示:
def upload_with_dropzone
if params[:document]
@resume = @p.documents.new(document_params)
if verify_recaptcha(model: @resume)
@resume.save
session[:resume_id] = @resume.id
redirect_to prospect_upload_path
else
flash[:error] = "Cannot upload image"
redirect_to prospect_upload_path
end
end
在其他操作中,我调用session[:resume_id]
但它返回nil
def upload_resume
if session[:resume_id].present?
@resume = Document.find(session[:resume_id])
elsif params[:interaction] && (1..5).include?(params[:interaction][:interaction_rating].to_i)
@resume = @p.documents.last
@itr.update(interaction_feedback_params)
else
@resume = @p.documents.new
end
end
以下是我的routes.rb
:
match "/upload" => "upload#upload_resume", via: [:get, :post]
post "/upload_resume" => "upload#upload_via_dropzone"
出了点问题,请给我一个想法!
我在byebug
行之后添加了session[:resume_id] = @resume.id
,并且我debug会话[:resume_id]