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?
“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 1:51:38 PM UTC+1, powi wrote:
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.
The 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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.