Created
September 17, 2015 16:58
-
-
Save brennovich/8fa78a1c993aad7a04ec to your computer and use it in GitHub Desktop.
Quick and simple example of how output active menu class for Rails applications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example: | |
# | |
# Let's say we're are accessing a new form to create a Post, probably | |
# our page will be rendered by PostsController and new action: | |
class PostsController < ApplicationController | |
def new | |
@post = Post.new | |
render :new | |
end | |
end | |
# If we want to add class `active` into our menu view we need to | |
# specify when it should be active for the active_menu_class helper: | |
# | |
# app/views/posts/new.html.erb | |
<ul id="menu"> | |
<li class="<%= active_menu_class('posts', 'new') %>">Novo Post</li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment