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
endNoMethodError: undefined method `[]' for nil:NilClassThe cookies middleware in rails doesn't look like it has changed. However env["actiondispatch.cookies"] is only set lazily - perhaps previously there was some other middleware that was causing it to be set for you? If so then you need to set env["actiondispatch.cookies"] if it is nil
If you create an actiondispatch::request rather than rack::request then you'll get a cookies method on request that does that for you.
Fred