Question

I have an elementary problem. I'm sure you can tell by the question that I am somewhat new to ruby and rails.

I have a navigation that I am trying to apply the "active" class to so I can style the active page differently. I have @cur_page set like this with a before_filter:

def cur_page
    @cur_page = params['action']
end

I am trying to simply output the text "active", but its not working.

<li class="button <%= "active" if @cur_page == "contact" %>"><%= link_to "Contact", :public_contact %></li>

I've also tried:

<li class="button <%= puts "active" if @cur_page == "contact" %>"><%= link_to "Contact", :public_contact %></li>

I've checked the instance variable to make sure that it is set, and it is displaying "contact" like I expect.

Any ideas?

Was it helpful?

Solution

What is the :public_contact? I would recommend you to use current_page? helper instead of @cur_page.

<li class="button <%= "active" if current_page?(public_contact_path(@contact) %>"><%= link_to "Contact", public_contact_path(@contact) %></li>

Replace public_contact_path(@contact) to valid route helper.

OTHER TIPS

I think the problem is with double quotes.

use 'active' instead of "active" use 'contact' instead of "contact"

<li class="button <%= 'active' if @cur_page == 'contact' %>"><%= link_to "Contact", :public_contact %></li>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top