I want to build an app which handles multiple pages, and the user can add to the app (from a form) a page, then add the added page to a pages table. (Normally)
All of this I know how to do and I don't have any issues at it.
The problem is that I want to create a menu in application.html.erb, but I need to get the pages table data from a controller, so I tried to pass regular instance variables from application_controller.rb to application.html.erb, and it didn't work.
In application_controller.rb:
@foo = "bar"
In application.html.erb:
<%= @foo %>
I don't even get an error, there is just nothing in the view. (I mean the variable isn't there, I can still see other content)
How can I attach a controller for application.html.erb? (Or pass variables to application.html.erb) Thanks for any help.
SOLUTION: In you application_controller you can do
before_action :set_page
def set_page
@foo = "bar"
end
This will run the set_page action before every action in your application which should accomplish what you want.
Thanks to ruby_newbie!!!!