Normally I have:
cookies[:location] = { :value => { :city => 'foo', :country => 'bar' } }
However, sometimes :country is not set. When I do:
cookies[:location][:country].present?
to check if country has been set, it returns an error:
[:country] is not a symbol
How would I check to see if a country is set in cookie[:location] if I cannot do it this way?
You
cookieshash is nested differently than you are expecting::valueis nested under:location,:cityand:countryare nested under:value. Here is some irb output to get you started:If you nest the hash like below, you will get your expected behavior: