How can I declare a global variable in ruby on rails? <p>How can I declare a global variable in "ruby on rails"?</p> <p>sample code:</p> <p>in my controller#application.rb:</p> <pre><code>def user_clicked() @current_userid = params[:user_id] end </code></pre> <p>in my layout#application.html.haml: I have sidebar with this link</p> <pre><code>= link_to "John", user_clicked_path(:user_id =&gt; 1) = link_to "Doe", user_clicked_path(:user_id =&gt; 2) = link_to "View clicked user", view_user_path </code></pre> <p>in my views#view_user.html.haml:</p> <pre><code>%h2 @current_userid </code></pre> <p>I hope you will understand the logic and what I am trying to say. I'm a noob in ruby on rails. Please help ^_^</p> <p>I want to declare a global variable that can modify my controller and use it anywhere, like controller, views, and etc.<br> The above is only a sample scenario. If I click the John or Doe link, it will send a user_id to the controller and when I click the "View clicked user" link, it will display the last clicked link. It is either John=1 or Doe=2.<br> Of course if I click the "View clicked user" link first, it will display nil.</p>