Problem Changing Cookie Value in Rails 3

I am trying to change the cookie for the location of users in the front filter, but I am having problems:

A cookie is set to 1 correctly if it does not exist but is not permanently stored and returns to 1 for any subsequent requests.

  def remember_location(loc = nil)
    cookies.permanent[:location] = 1 if cookies[:location].nil?
    loc = Location.find(loc).try(:id) rescue nil
    unless loc.nil?
      # cookies.delete :location    # => this doesn't work either
      cookies.permanent[:location] = loc
    end
    cookies[:location]
  end
+5
source share
1 answer

Here is the problem. The places I went into later led to a Rails error because the database was not completely full. A cookie will not actually be saved unless the entire endpoint request completes successfully.

Having looked at the source code of ActionDispatch :: Cookies, it certainly looks like this: http://api.rubyonrails.org/classes/ActionDispatch/Cookies.html

+1

All Articles