Reputation: 177
I want to be able to display a different menu item if a post exists in a certain page, but unsure of how to best call the controller method in a partial.
I have a career page and if there is a post within that page I would like to display 'NEW' next to the career item in my menu, if no post exist then I just want it to display 'Careers'.
_header located in views -> layouts
<% if Careers.exists?(:id) %>
<li><%= link_to 'Careers NEW', careers_path %></li>
<% else %>
<li><%= link_to 'Careers', careers_path %></li>
<% end %>
Upvotes: 1
Views: 71
Reputation: 3339
try this:
<li><%= link_to "Careers #{(Career.present?)? 'NEW' : ''}", careers_path %></li>
Upvotes: 2