Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] Memoize cookies so they can be retrieved in the same response / request cycle

#2733

If you set a cookie in a controller action and then try and access the new value in later in the action or in the view, the old value for the cookie is retrieved because the CookieJar is re-initialized with each call to ActionController::Base#cookies.

# Contrived example
# Before patch:
def show
  cookies[:logged_in] = true
  cookies[:logged_in] # => nil
end

# After patch:
def show
  cookies[:logged_in] = true
  cookies[:logged_in] # => true
end

Related thread on Core mailing list.

Reported by Olly · May 28th, 2009 @ 01:40 PM

State: resolved
Milestone: 2.3.4
Assigned to: josh josh
Importance: High

Activity

  1. josh
    josh
    • Milestone cleared.
    • State changed from new to open
    • Assigned user set to josh

    May 28th, 2009 @ 03:10 PM

  2. Repository
    Repository
    • State changed from open to resolved

    May 28th, 2009 @ 03:35 PM

  3. Repository
    Repository

    (from [143c55d325388aa2384de8f137cfb61c09912208]) Memoize cookies so that updates to cookies are available in the current request. [#2733 [PATCH] Memoize cookies so they can be retrieved in the same response / reque... state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com

    Conflicts:

    actionpack/test/controller/cookie_test.rb
    

    http://github.com/rails/rails/commit/143c55d325388aa2384de8f137cfb6...

    July 21st, 2009 @ 10:47 PM

  4. Bryan Helmkamp
  5. Jeremy Kemper
    Jeremy Kemper
    • State changed from resolved to open
    • Milestone set to 2.3.4

    Bryan ran into a regression with this.

    August 10th, 2009 @ 11:50 PM

  6. John Pignata
    John Pignata

    Bryan -- I'm not sure that this actually did introduce a regression. Your test seems to work when I call cookies.clear against the controller which is how the other tests interact with it

      def test_cookies_are_clearable_from_test
        get :authenticate
        @controller.send(:cookies).clear
        response = get :count
        assert_equal "0", response.body
      end
    

    August 25th, 2009 @ 04:57 AM

  7. josh
    josh
    • State changed from open to resolved

    Reresolving.

    We should update the functional test cookie accessor to behave more like the integration one.

    August 31st, 2009 @ 07:45 PM