Question

I try to use current_page? method in my navbar this way:

<ul class="nav pull-right">
      <li class="<%="active" if current_page?(controller: :welcome)%>"><%= link_to "Home", "/"%></li>
      <li class="<%="active" if current_page?(controller: :products)%>"><%= link_to "Store", "/products"%></li>
      <li class="<%="active" if current_page?(controller: :catalog)%>"><%= link_to "Catalog", "/catalog"%></li>
...

Everything works fine when I move between pages. But when I try to go to /admin which is provided by rails_admin I get 500 internal server error in response. This is probably caused by current_page? method because if I remove them from layout everything works fine.

I'll appreciate any solution.

Was it helpful?

Solution 2

I just disabled using default layout by adding layout false in devise session controller and everything works fine now. Thanks!

OTHER TIPS

In case anyone runs into this and wants to fix it, you need to use absolute urls in the way you pass parameters to current_page?

So in your case, this code will work:

<ul class="nav pull-right">
  <li class="<%="active" if current_page?(controller: '/welcome')%>"><%= link_to "Home", "/"%></li>
  <li class="<%="active" if current_page?(controller: '/products')%>"><%= link_to "Store", "/products"%></li>
  <li class="<%="active" if current_page?(controller: '/catalog'')%>"><%= link_to "Catalog", "/catalog"%></li>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top