Answer the question
In order to leave comments, you need to log in
How to set a class for certain pages?
Hello. There is such code:
In application.html.haml
- if user_signed_in?
%nav.navigation
%ul
%li
= link_to "New project", new_place_path
%li
= link_to "Profile"
%li
= link_to "Sign Out", destroy_user_session_path, method: :delete
- else
%nav.navigation_welcome
.inner
%ul
%li
= link_to "Login", new_user_session_path
%li
= link_to "Sign up", new_user_registration_path
Answer the question
In order to leave comments, you need to log in
$(function () {
var url = window.location;
$('#top-menu a[href="' + url + '"]').parent('li').addClass('current-page');
$('#top-menu a').filter(function () {
return this.href == url;
}).parent('li').addClass('current-page').parent('ul').slideDown().parent().addClass('active');
});
<div id="top-menu">
<ul class="nav child_menu">
<li><a href="index.html">Ololo</a></li>
<li><a href="index2.html">Ololo2</a></li>
</ul>
</div>
<li class="current-page"><a href="index2.html">Ololo2</a></li>
You can write your own helper, you can make before_action in your HomeController, which will set the variable.
maybe on the forehead
You can bind not to the controller, but to request.url
The best way is to use angular)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question