In my view, I have:
<li class="<%= 'active' if current_page?(:controller => 'posts') %>"><a href="/posts">Posts</a></li>
The problem is, when I move away from /posts/ path, the class is turned off again. For example, when I go to /posts/1, the link class is not active anymore. I thought it would still be active because the controller stays the same. How should I fix the problem?
You can do
<%= 'active' if params[:controller] == 'posts' %>
so try to debug what's the value of
params[:controller]
when you go to /posts/1 to see why class "active" doesn't appear.
It could be that the class "active" is there but its not showing for a css issue? Check the source code on the browser on /posts/1* to see if the code is working or not