I would like to do something like using instance variables
def index
@balance=1000
enb
def increment
@balance+=1
end
what kind of variable should i use?
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.
There are different ways to interpret your question, not sure which you meant:
All actions (in the same or different controllers) can use instance variables with the same name. But only 1 action is called per HTML request/response cycle.
If you want an instance variable to be set in one action and have the same value in another action (as part of a different request from the same web browser), use the Session store. Eg