Skip to content

Commit

Permalink
nav links are highlighted when active
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Huneycutt committed Oct 22, 2012
1 parent 9932536 commit 380c68d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ body {
a {
color: $text;
text-decoration: none;
&:hover {
&:hover, &.active {
color: orange;
}
&:active {
Expand Down
13 changes: 13 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@ module ApplicationHelper
def inside_layout layout = 'application', &block
render :inline => capture_haml(&block), :layout => "layouts/#{layout}"
end

def nav_link_active?(link)
case link
when :details
"active" if action_name == "photography_details"
else
"active" if action_name == link.to_s
end
end

def nav_link_options(link)
{:class => 'active'} if nav_link_active?(link)
end
end
12 changes: 6 additions & 6 deletions app/views/layouts/side_navigation.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
%section.side_navigation
%h2.first Photographs
%ul
%li= link_to "Newborns", newborns_path
%li= link_to "Kids", kids_path
%li= link_to "Families", families_path
%li= link_to "Details", "/photography-details"
%h2= link_to "Private tutoring", classes_path
%h2= link_to "About me", about_path
%li= link_to "Newborns", newborns_path, nav_link_options(:newborns)
%li= link_to "Kids", kids_path, nav_link_options(:kids)
%li= link_to "Families", families_path, nav_link_options(:families)
%li= link_to "Details", "/photography-details", nav_link_options(:details)
%h2= link_to "Private tutoring", classes_path, nav_link_options(:classes)
%h2= link_to "About me", about_path, nav_link_options(:about)

%section.side_navigation_body
= yield

0 comments on commit 380c68d

Please sign in to comment.