title: How do I apply an 'active' class to my navigation based on the current_page in a DRY way? - Rails 3
body: <p>So in my <code>application.html.erb</code> I have my navigational structure that looks something like this:</p>
  
  <pre><code>&lt;div id="navigation"&gt;
              &lt;ul class="pills"&gt;
                      &lt;% if current_page?(:controller =&gt; 'welcome', :action =&gt; 'index') %&gt;
                          &lt;li&gt;&lt;%= link_to "Profile", vanity_path(:vname =&gt; current_user.username) %&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;%= link_to "Settings", settings_path %&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;%= link_to "Sign Out", signout_path %&gt;&lt;/li&gt;
                      &lt;% elsif !current_page?(:controller =&gt; 'welcome', :action =&gt; 'index') %&gt;
                          &lt;li&gt;&lt;%= link_to "Home", root_path %&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;%= link_to "Profile", vanity_path(:vname =&gt; current_user.username) %&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;%= link_to "Settings", settings_path %&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;%= link_to "Sign Out", signout_path %&gt;&lt;/li&gt;              
                      &lt;% end %&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>However, what I would like to do, is once they are on any of the pages in the navigation, it applies a class <code>active</code> to the respective link.</p>
  
  <p>So for instance, if the user is on <code>mydomain.com/johnbrown</code> which is the <code>Profile</code> link, the rails helper would look something like this:</p>
  
  <p><code>link_to "Profile", vanity_path(:vname =&gt; current_user.username), :class =&gt; "active"</code>.</p>
  
  <p>But how do I do that in a programmatic way, so I am not duplicating content? i.e. how do I get that functionality for all the pages in my navigation and write it as DRY as possible?</p>
  
  <p>Thanks.</p>