質問

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