guys!
Prior to asking i should mention, that i`m working without ActiveRecord or any self-hosted-database. So thats why i have to store some values in the session.
From the very begining i desided to set session value of the users city in the layout. – i supposed it would be loaded before anything else. So i`ve done something like this:
<% session[:city] ||= {:name => 'City-Name', :lat => '40', :lng => '40'}%>
But when i`m loading directly to inner page it occurs that session[:city is nil *(
How should i set the session properely, so that it wouldn`t be nil???
I had similar needs in one of the applications I worked on. It needed the users data to be loaded on sign-in and stored in the session. So, wrote a module called session_helpers.rb with the following:
You can make any or all the methods available to views as well:
From the model I would retrieve a hash of the data that needs to be put up in the session about the user:
As I wanted to do this after sign-in I overrode the devise method to do this:
This way I was able to load important data about the user on sign-in and store it in the session and retrieve whenever I wanted. Hope this helps.