0

I try to save my variable in an action to call it from another action in my controller. I use session to save it like below:

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

In other action I call session[:resume_id] but it return 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

Below is my routes.rb:

match "/upload" => "upload#upload_resume", via: [:get, :post]
post "/upload_resume" => "upload#upload_via_dropzone"

Something was wrong, please give me an idea!

I put byebug after session[:resume_id] = @resume.id line, and I debug the session[:resume_id]

  • can you confirm that the execution reaches the line where the resume id is saved in the session? Put a debug statement next to that line and check that it executes. – Toby 1 Kenobi Aug 30 '17 at 07:35
  • I upload about the debug – Thanh Khac Aug 30 '17 at 07:45
  • I had similar problem, but with the hanami app. It turned out that the problem was in the incorrect session secret set up. I know that's not an answer but it may provide you some food for thought. – lightalloy Aug 30 '17 at 10:14
  • It could be issue with session initialisation. To make sure that session is initialise assign something to session before you read. https://stackoverflow.com/questions/14665275/how-force-that-session-is-loaded – Piotr Galas Aug 30 '17 at 12:52
  • Your action is called `upload_with_dropzone` but in your routes you have `upload_via_dropzone` – Toby 1 Kenobi Aug 30 '17 at 17:25
  • @Toby1Kenobi I edited it, but it still not work – Thanh Khac Aug 31 '17 at 03:51

0 Answers0