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 8172225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:42:53+00:00 2026-06-06T21:42:53+00:00

This might be a very simple question, but I could not find the answer

  • 0

This might be a very simple question, but I could not find the answer for it. How should I access a rails session variable from javascript/jQuery (from a Backbone view)? Most likely this is not the best practice, but this is not a problem for me.

Thank you,
Alexandra

  • 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-06-06T21:42:55+00:00Added an answer on June 6, 2026 at 9:42 pm

    You can use the gon gem. It allows to send data automatically with each request and let it be accessible from javascript.

    For example, after including the gem in your Gemfile, you can add a before filter to your ApplicationController:

    class ApplicationController < ActionController::Base
    
        before_filter :set_gon
    
        ...
    
    
        protected
        def set_gon
           gon.my_session_variable = session[:my_session_variable]
        end
    end
    

    In your application layout, section head of your html:

    <%= include_gon %>
    

    Now you can read this value from your javascript:

    alert(gon.my_session_variable)
    

    This way you only include data specific to the request in your ajax response, and all your extra info is available from the gon variable.

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

Sidebar

Related Questions

This question might appear very simple, but i haven't found an answer yet, so
This might be a very newbie question, but I didn't find anything satisfying I
I know, this might be a very basic question but I am not 100%
This might be a very simple question but i am unable to get it.
Ok, this might be a very noob question, but I find that PHP Documentation
This might seem like a very simple question, but I am struggling with it.
This might be a very simple question but after much searching on different forums
This might be a very simple question but didn't yield any results when searching
The answer to this might be very simple, but I don't know it. The
I know it might be a very simple solution for this, but I am

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.