1

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 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.