In java, jsf it would be something like private string x ["SessionScope"] or something like that.
But how to do this in rails?
I need to create a session scoped variable in one view to use it in another.
1 Answer
First look in the documentation about the Session
There is variable, a hash that keeps session data. It can be used inside controller, view, etc.
For example.
Controller
class HomeController < ApplicationController
def first
session[:var] = "data"
end
def second
puts session[:no_var]
puts session[:var]
end
end
If you first visit action first, it will set the session has with key :var to "data", and later when you visit second action it will print
nil
data
If in other session you first visit second action it will print.
nil
nil