Search code examples
ruby-on-railsrubyruby-hash

Access Hash inside helper of another page


I currently have a helper titled directors_helper.rb with a hash predefined inside of it.

module DirectorsHelper
   def dirs = {
      gm: { pos: "General Manager", email: "123@abc.com" },
      prod: { pos: "Production Director", email: "456@def.com" },
      support: { pos: "Support Director", email: "789@xyz.com" }
   }
   end
end

Anything under the directory /app/views/directors is able to access the content of the helper and thus the hash. Any attempt to call <%= dirs[:gm][:pos] %> inside a directory thats not directors gives me the error undefined local variable or method 'dirs' Is it possible to have my hash globally accessible throughout my project?


Solution

  • Turns out it was as simple as going into the controller of the page that I wanted to have access to the directors helper and including helper DirectorsHelper in it.