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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:35:25+00:00 2026-06-02T16:35:25+00:00

I need some clearance on scope of instance variables in rails application (not sure

  • 0

I need some clearance on scope of instance variables in rails application (not sure if other frameworks have the similar paradigm)

Lets say I have an instance variable

@page_count = some_value

inside a controller’s index action

So, regarding accessibility of this variable. It should be accessible within its view and I guess from model as well.(right?)

Now, if i call some other action(through other request) say, export in the same controller, the variable @page_count wont have its value which was set inside index action

(instance variable would not retain its value between different requests, right?)

Currently to deal with this I am using session scoped variable,

session[page_count] = some_value # inside index action

Now the variable will be available inside other actions, including the export action ( through other request)

Is this is good approach? using sessions? or there are better alternatives for storing values between different requests?

Suggestions/Comments/pointers, please?

  • 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-02T16:35:26+00:00Added an answer on June 2, 2026 at 4:35 pm

    I think it depends on what you set @page_count to.

    If it’s like the number of rows in a db table ‘pages’, and you set it like,

    @page_count = Page.all.count
    

    Then you could use a before_filter and set the value there for every controller action you need it. Here’s some more info on filters.

    Otherwise, if the value of @page_count is something calculated and changes per action, then I think you just have to define it in every action.

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

Sidebar

Related Questions

Need some help here. I have deployed spree (0.70.3) on slicehost (ubuntu, ruby1.8.7, Rails
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some best practice advice here... Navigation based application. Root view is a UITableView
Need some help with a query.. I have three tables. Source id name 1
Need some advice to use iframe for widget or not. Will some addons/plugin block
Need some insight on how this works I have the following piece of code
Need some help with below issue We have 2 machines, each of these machines
Need some guidance. I have java webstart app and I want it to connect

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.