0

Objective: Display specific links in navigation bar for specific routes based on the currently viewed page.

I would like to do something like this in my application.html.haml

if companies_page %li = link_to "Contact Us", contact_path

If there is a better way to do this I am open to suggestions. Thank you!

craig.kaminsky
  • 5,588
  • 28
  • 31
szier
  • 1,427
  • 3
  • 19
  • 32
  • Clarification: are you looking to display specific links in the navigation bar for specific routes *based on what page is currently being viewed*? – craig.kaminsky Mar 03 '16 at 17:43
  • Yes, that is correct – szier Mar 03 '16 at 17:47
  • 2
    Ok ... I think this SO answer might help you: http://stackoverflow.com/questions/31280230/rails-4-bootstrap-3-how-to-display-a-different-navigation-bar-on-different-pa – craig.kaminsky Mar 03 '16 at 17:49
  • How can i mark this as the answer? Thanks! – szier Mar 03 '16 at 17:57
  • I will go ahead and move it to an actual answer, which you can mark if you wish :) ... actually, when I move it to an answer it's "too trivial" and it moves it back to a comment LOL – craig.kaminsky Mar 03 '16 at 17:58

1 Answers1

0

You might think about using Tabulous which does pretty much exactly that; it allows you to define a set of possible tabs (which you can render as a navigation bar) and also when they should be visible and when they should be active. From the documentation example, part of a tab definition block might be:

visible_when   { in_action('any').of_controller('pictures') }

Since that's a block you could easily use more complex logic there, but I imagine that would get very hard to conceptualize very quickly.

pjmorse
  • 9,204
  • 9
  • 54
  • 124