Reputation: 1098
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?
Upvotes: 0
Views: 642
Reputation: 5929
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.
Upvotes: 1
Reputation: 826
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>
Upvotes: 0