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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:39:13+00:00 2026-05-25T19:39:13+00:00

Question 1: What is the scope of an instance variables in Rails actions (methods).

  • 0

Question 1:

What is the scope of an instance variables in Rails actions (methods). Does each connection to the server form a new instance of a controller?

For example:

  • User_A loads a ‘setter’ page, causing a random instance variable called @randInt to be generated.
  • User_B (from another PC elsewhere) loads a ‘getter’ page, requesting @randInt.

Will User_B retrieve the @randInt set by User_A? Or is that instance variable unique to User_A’s connection?

Question 2:

Question 2 is the same as question 1, but using @@randInt instead. If the answer to Question 2 is, "yes, both users can see this value," is it an acceptable practice to use global variables in Rails to store temporary data that you want to share among multiple users?

  • 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-25T19:39:13+00:00Added an answer on May 25, 2026 at 7:39 pm

    Question 1: No, instance variables are shared only in the instance, where ‘instance’ refers to the instance of the controller, and so these variables only last one request (so User_B will receive a different @randInt).

    Question 2:: @@ variables are not global variables, $ variables are. @@ are class variables. As the link explains, different machine instances (such as if you’re using FCGI) will not share global ($) variables, so don’t use them.

    If you require global constants, set them in the config. Global variables are probably better left in the database (I can see a use for them, such as site settings, but the uses seem best suited to use with a database).

    You could use class variables as persistant instance variables, but again you might be better of using a database to store such values as you’re not guaranteed against your classes being reloaded (therefore resetting any class variables).

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

Sidebar

Related Questions

Simple question: Is the scope of require_once global? For example: <?PHP require_once('baz.php'); // do
I have a generic question about scope and encapsulation. Take two scenarios: Scenario 1:
The scope of my question is solely ASP.NET, as the answer may be different
Note: This question has broadened in scope from previous revisions. I have tried to
Basically this is a question how to access local scope handler. I trying to
I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code
My question is regarding the scope of the object created in +planet. I have
I have a superclass and a subclass, both of which define instance variables. Rough
Yet another static question. I have read the following: What are static variables? file
This question is limited in scope to HotSpot generations . Is there any way

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.