I have a model an a controller for a pages resource.
I need to be able to access the names of the pages
and the pages and link_to from within the
Application.html.erb
I have tried rendering a navigation partial.
But you can’t access the controller from a partial.
I need to be able to render a navbar that has access
the @pages variable so I can loop through them.
What’s the best way to do this?
Inside your ApplicationController,
app/controllers/application_controller.rbThis way you’re able to use the
@pagesinstance variable from within any view.By using memoization through the
||=operator you’re only assigning the variable the first time you need it, so no need to worry about calling that method every time.