Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6556303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:55:40+00:00 2026-05-25T12:55:40+00:00

guys! Prior to asking i should mention, that i`m working without ActiveRecord or any

  • 0

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???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:55:41+00:00Added an answer on May 25, 2026 at 12:55 pm

    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:

    module SessionHelpers
      def get_value(key)
        session[key.to_sym]
      end
    
      protected
        def store_data(*objects)
          objects.each do |object|
            if object.is_a?(Hash)
              object.each do |key, value|
                session[key.to_sym] = value
              end
            end
          end
        end
    
        def remove_data(*objects)
          objects.each do |object|
            if object.is_a?(String)
              key = to_id(object)
            else
              key = to_id(object.class.name)
            end
            session[key] = nil
          end
        end
    
        def update_data(key, value)
          session[key.to_sym] = value
        end
    
      private
        def to_id(name)
          "#{name.parameterize('_').foreign_key}".to_sym
        end
    end
    

    You can make any or all the methods available to views as well:

    # application_controller.rb
    helper_method :get_value
    

    From the model I would retrieve a hash of the data that needs to be put up in the session about the user:

    def common_data
      @data = Hash.new
    
      @data.merge!( { 'news'         => self.news.count } )
      ...
      @data
    end
    

    As I wanted to do this after sign-in I overrode the devise method to do this:

    def after_sign_in_path_for(resource_or_scope)
      store_data( '_count', current_user.common_data )
    
      dashboard_path
    end
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that searches a database of addresses. The page visitor enters
Guys i have stored a null value in the column of sqlite database the
Guys, I have a CSS Layout that I am using that has a header,
Guys, I have the following code that is inside a big while loop that
Guys, I have a query where basically select the latest browser that our user
guys, I have the problem when copying database from local assets folder to /data/data/package_name/databases
guys! I am working on a project, which has to have same (as possible)
Guys, what is function called after my class loaded, where i can call self
guys please post me an example for threading in MFC....it should show the progress
guys i have arrays in which i have to match this kind of text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.