When working in Rails, I encountered an issue with changing the class of an li element based on whether the page is active or not. I attempted to use an application helper function for this purpose, but unfortunately, the code did not work as expected when placed within the element itself. However, when I moved the code outside the element (for example, within p tags), it worked fine.
Here is a snippet from my application helper file:
def activepage(path)
' class="active"' if current_page?(path)
end
Below is how the sidebar partial is structured:
<li<%= activepage(root_path) %>>
<a href="blank-page.html"><i class="fa fa-fw fa-file"></i> Blank Page</a>
</li>
It seems that the li element does not get created properly when the page loads. Does anyone have insights into why this might be happening and suggestions on the most elegant way to resolve this issue? Your help is greatly appreciated!
Thank you!