jshbrmn
jshbrmn

Reputation: 1787

Why are my Rails cookies lost upon browser close?

I understand that Rails requires some configuration to get the cookies to persist upon browser close. The cookie sets properly and I am able to get the desired result while the browser remains open. However, as soon as I close the browser and re-open it and access the site, the cookie data seems lost.

I did this in the appropriate controller:

cookies[:locale] = { value: params[:locale], expires: 1.year.from_now }

I also did this in session_store.rb:

myApp::Application.config.session_store :cookie_store, {
  :expire_after =>  nil,
}

A simple command seems likely. What am I missing?


EDIT full conditional for clarity -

def lang_set
 if params[:locale] != nil
  cookies.permanent[:locale] = params[:locale]
 end
 I18n.locale = cookies[:locale]
end

Upvotes: 1

Views: 770

Answers (1)

NM Pennypacker
NM Pennypacker

Reputation: 6952

def lang_set
 if params[:locale] != nil
  cookies.permanent[:locale] = params[:locale]
 end
 I18n.locale = cookies[:locale]
end

Upvotes: 1

Related Questions