I am stumped. I want to use an instance variable in my navbar to show dynamic content from a table.
In terms of file structure, within my Views, I have a /layouts folder. Within that folder, there is a _header.html.erb for the navbar that is placed in the view through <%= render 'layouts/header' %> in application.html.erb file.
Now here's where it gets sticky. In my navbar, I have a set of links. I want it to render an instance variable as a link (the text it shows, not the path), so I am writing:
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "About", about_path %></li>
<li><%= link_to "Settings", edit_user_registration_path %></li>
<li><%= link_to "My Example", myexample_path %></li>
<li><%= link_to @example, stack_path %></li>
</ul>
I have tried doing two different things with the instance variable.
So I need to define @example = Stack.where(user_id: current_user.id).pluck(:points) to return a number that I want to place in that navbar. I have tried putting that instance in the Application Controller and by making a Layouts Controller and placing it there in def index.
Therefore, my question is: to create an instance variable to be read by this _layouts.html.erb file, which controller is appropriate to use?
As a final note, whether I add it to the Application Controller or Layouts Controller, it simply doesn't render. If I remove the @example instance and instead put static text, it will add it to the navbar. So this seems to be my issue.