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