Rails session store stopped working correctly

Reddirt

I have a Rails 3.2 app that uses session store in the controllers to get the user back to the screen they were previously on.

It's been working fine for over a year. All of a sudden, the production version on Heroku, has started having issues. The user is looking at a worequest and clicks on the following in order to add a comment.

<%= link_to 'New Comment', new_comment_path(:worequest_id => @worequest.id), :class => 'btn btn-primary' %>

This is the code I use:

 def new
    @comment = Comment.new
    @comment.build_attachment
    @worequest = params[:worequest_id]
    session[:return_to] ||= request.referer

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @comment }
    end
  end

  # POST /comments
  # POST /comments.json
  def create
    @comment = Comment.new(params[:comment])

    respond_to do |format|
      if @comment.save
        if session[:return_to] != nil
          format.html { redirect_to session.delete(:return_to), notice: 'Comment was successfully created.' }
          format.json { render json: @comment, comment: :created, location: @comment }
        else
          format.html { redirect_to :back, notice: 'Comment was successfully created.' }
          format.json { render json: @comment, comment: :created, location: @comment }
        end
      else
        format.html { render action: "new" }
        format.json { render json: @comment.errors, status: :unprocessable_entity }
      end
    end
  end

In development and staging (on Heroku), the user goes back to the worequest after entering a new comment.

Now in Production, the url looks like this:

mywebsite/comments instead of mywebsite/worequests/639

I'm not even sure where the session[:return_to] gets stored. Therefore, I'm having trouble debugging the issue.

Thanks for your help!!

mkirk

Are you able to replicate this behavior 100% of the time, or just seeing it sometimes in your log?

It looks like someone is getting to comments#new from /comments (comments#index). Is there a route to /comments?

Run rake routes to see all your routes.

If there is a route to comments#index, and there's no reason for it to be exposed because you only intend for people to post comments from within the context of a specific article, consider removing it the comments#index route.

Also, one thing to consider, request.referrer is not always available. It's sent by the client who may choose not to send it (e.g. certain privacy extensions remove this header).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

session not working correctly in yii

My session ID's stopped working

PHP Session Suddenly Stopped Working For Some Pages

Working with Redis to store Session - Django

Rails session data - Store in a hash

Rails: How to store data in session?

Rails ActiveRecord store and new session

Session stopped working when i was working with config.php in codeigniter

Project stopped working after downgrading Rails version

Rails 3.2 with Devise: logout link stopped working

Rails 4 - association not working correctly

Rails Strip Method Not Working Correctly

Timer function not working correctly when stopped and started multiple times

PHP isset function for website session not working correctly

PHP Session not working correctly on a particular host

Guest session stopped working on Ubuntu versions later than 16.04

Why is session store initializer removed in Rails 5.1.1

Rails app with different session store for each model

Rails 4 - JavaScript stopped working, getting: undefined is not a function

Rails 4 / Capistrano 3 Deployment Stopped Working (no errors)

Ruby on Rails and Zurb Foundation Offcanvas not working correctly

Rails polymorphic dependent: :destroy not working correctly

Rails secure session and cookies are not working with a CDN

reset_session in rails 3.2 is not working

Session.Timeout not working correctly in ASP Classic / IIS

after migrate to .net core 2.0 session stop working correctly

Java File.setWritable() and stopped working correctly after JDK 6u18

Redux returning an empty arrays in store - Reducer not working correctly?

Why has my remote connection stopped working, despite active TMUX session?