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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Yes, you could use an instance variable for this as long as everything is happening in a single request.
So something like this:
will work as expected. However, this sort of thing:
won’t work if
where_isandmangleare called in difference requests.Remember that the lifetime of a controller instance is a single request.