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

  • Home
  • SEARCH
  • 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 6327523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:17:45+00:00 2026-05-24T17:17:45+00:00

I have a controller. In the controller I have two methods. I would like

  • 0

I have a controller. In the controller I have two methods. I would like a variable whose value is set in method 1 to be accessible in method 2. Could I use an instance variable to achieve this?

  • 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-24T17:17:46+00:00Added an answer on May 24, 2026 at 5:17 pm

    Yes, you could use an instance variable for this as long as everything is happening in a single request.

    So something like this:

    class PancakesController < ApplicationController
      def where_is
        @house = Pancake.find(params[:id])
        render :json => mangle, :status => :ok
      end
    
    private
    
      def mangle
        @house
      end
    end
    

    will work as expected. However, this sort of thing:

    class PancakesController < ApplicationController
      def where_is
        @house = Pancake.find(params[:id])
        #...
      end
    
      def mangle
        if(@house)
          #...
        end
        #...
      end
    end
    

    won’t work if where_is and mangle are called in difference requests.

    Remember that the lifetime of a controller instance is a single request.

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

Sidebar

Related Questions

In my users_controller I have two methods signup_process and login . I would like
I have a Controller with two Edit methods (see below). When I submit the
I have a model called Details, and two controller methods new and create. New
Can somebody explain me one thing. I have two methods in my controller :
I have a long running Service method (doing business logic) and I would like
In my Asp.net MVC app, I have two methods on a controller, one for
I have two view controller classes in my application delegate. I can change from
I have a NIB with two NSWindow objects. The controller class has two IBOutlets,
Let's say I have an User entity and I would want to set it's
I have two very similar specs for two very similar controller actions: VoteUp(int id)

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.