This project is archived and is in readonly mode.

#6108 ✓stale
Michael Reinsch

ActiveRecord session store clobbers params

Reported by Michael Reinsch | December 3rd, 2010 @ 08:30 AM

This is with Rails 3.0.3, using the ActiveRecord session store. I'm using routes like this:

  scope "(:locale)", :locale => /en|ja/ do
    root :to => 'home#index'
    match 'some' => 'home#some'
  end

And in the controller:

  before_filter :set_locale
  before_filter :redirect_to_locale_path

  private
  def set_locale
    I18n.locale = params[:locale]
  end

  def redirect_to_locale_path
    unless params[:locale]
      redirect_to :locale => I18n.locale
    end
  end

This works fine with cookie session store, but when using the ActiveRecord session store with :cookie_only => false the params are empty.

I put sample code on github: https://github.com/mreinsch/activerecord_sessionstore_clobbers_params

To reproduce the issue:

git clone git://github.com/mreinsch/activerecord_sessionstore_clobbers_params.git
cd activerecord_sessionstore_clobbers_params
rake db:migrate
rake

This will print params.inspect to stdout and you'll see that the tests are failing because params[:locale] is not set.

Comments and changes to this ticket

  • Michael Reinsch

    Michael Reinsch December 6th, 2010 @ 07:01 AM

    Debugging this further revealed that this issue actually comes from ActionDispatch::Session::AbstractStore#extract_session_id, so this impacts any session store supporting :cookie_only => false.

    My findings so far:

    ActionDispatch::Session::AbstractStore#extract_session_id calls request.params[@key] if :cookie_only is false. This is the first call to params and thus it combines the different parameters and caches the result in @env["action_dispatch.request.parameters"]. The issue here is that the path_parameters (@env["action_dispatch.request.path_parameters"]) aren't set yet.

  • rails

    rails March 14th, 2011 @ 12:00 AM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails March 14th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages