title: How to use same variable across various controllers - ruby on rails
body: <p>I am using ruby 2.3.1 and rails 3.2.1. I need to initialize a variable called <code>has_sub_menu = false</code> in application controller. </p>
  
  <p>In my application i am using more than 30 controllers and only two controllers contains sub-menu, so i need to assign <code>has_sub_menu = true</code> to these controllers to validate it in layout file.</p>
  
  <p>This is my <code>application.rb</code></p>
  
  <pre><code>has_sub_menu = false
  </code></pre>
  
  <p>some_controller01.rb</p>
  
  <pre><code>has_sub_menu = true
  </code></pre>
  
  <p>some_controller02.rb</p>
  
  <pre><code>has_sub_menu = true
  </code></pre>
  
  <p>I tried like this in <code>layout.rb</code>,</p>
  
  <pre><code>if controller.has_sub_menu == true
    show_menu_items
  end
  </code></pre>
  
  <p><code>show_menu_items</code> will be available in that two controller and currently i am not able to access the <code>has_sub_menu</code> value in layout file</p>
  
  <p>I know in c# I can declare the variable as static and access it in any file using object. </p>
  
  <p>Like wise how can i declare a variable in <code>application</code> controller and assign different value to that variable in other two controller and I need to access that value in layout.rb file for sub-menu validation.</p>