I have a variable which contains a certain date based on certain criteria, which is established in the index action of my controller:
def index
if params[:y] && params[:m]
@date = ...
elsif
@date = ...
else
...
It is a bit more complicated than the example above, but you should get the idea. If I then want to use this variable within another action of the same controller, how do I do that? I would like it to be something like:
def new
@today = see index action
...
Thanks
There is No Way.
Every request creates an instance of controller. When hitting #index
, there is an instance. And the instance variables you defined can live there. When hitting "new", that's a new instance, the old instance variables are no longer there.
To remember something between requests, you can
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.