Check out Rails Internationalization (i18n) API: http://guides.rubyonrails.org/i18n.html. Section 2.3: It reads:
"You may be tempted to store the chosen locale in a *session* or a *cookie*. However, do not do this. The locale should be transparent and a part of the URL..." On Monday, August 17, 2015 at 8:51:38 AM UTC-4, powi wrote: > > In my Rails 3.2 setup I had the following middleware: > > module Rack > class Locale > def initialize(app) > @app = app > end > > > def call(env) > request = Rack::Request.new(env) > params = request.params > cookies = request.env['action_dispatch.cookies'] > session = request.env['rack.session'] > > > requested_locale = params['locale'] || cookies['locale'] || I18n. > default_locale > > > session['locale'] = cookies['locale'] = locale > > > @app.call(env) > end > end > end > > It was working fine until I've upgraded to Rails 4.0, where `cookies` is > nil and therefore I get the error: > NoMethodError: undefined method `[]' for nil:NilClass > > when `cookies['locale']` is called. What's the proper way to do this in > Rails 4.0? > > P.S. Rack also was bumped from 1.4.6 to 1.5.5. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/103ecb42-e664-4c9e-91fc-56a1b8d72e74%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

