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/089650d4-85d6-41cb-bb21-327560d79343%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to