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.

有帮助吗?

解决方案 2

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

其他提示

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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top