# Tracking website sections

**URL:** <https://www.ruby-forum.com/t/tracking-website-sections/171475>\
**Category:** Rails\
**Created:** [July 3, 2009, 6:57am UTC](https://www.ruby-forum.com/t/tracking-website-sections/171475 "2009-07-03T06:57:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vagabond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/258eb7/32.png) [@vagabond](https://www.ruby-forum.com/u/vagabond)\
**Post date:** [July 3, 2009, 6:57am UTC](https://www.ruby-forum.com/t/tracking-website-sections/171475/1 "2009-07-03T06:57:26Z")

</div>

I’d like some advise on how you handle marking website menus as  
‘selected’ so that you can show different states based on which  
section of a site you’re in.  
An example is using tabs like the illustration below. When in the  
first section, the tab has an outline and when moved to the next  
section, the second tab has the outline

±--------+  
| Menu #1 | Menu #2 Menu #3

```
     +---------+

```

Menu #1 | Menu #2 | Menu #3

To clarify, I know how to do the CSS etc. I’m looking for best  
practice on tracking this state in a Rails app.  
Once way that I have thought of is to link the menu to the current  
controller  
if controller == XYZ  
menu is selected  
else  
menu is normal  
end

This works in simple cases but doesn’t work well when using nested  
resources.

Thanks for the help

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)

[http://MyMvelope.com](http://MyMvelope.com) - The SIMPLE way to manage your savings

---

<div class="post-metadata">

**Author:** ![vagabond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/258eb7/32.png) [@vagabond](https://www.ruby-forum.com/u/vagabond)\
**Post date:** [July 3, 2009, 9:51am UTC](https://www.ruby-forum.com/t/tracking-website-sections/171475/2 "2009-07-03T09:51:25Z")

</div>

Andrew T. wrote:

> I’d like some advise on how you handle marking website menus as  
> ‘selected’ so that you can show different states based on which  
> section of a site you’re in.  
> An example is using tabs like the illustration below. When in the  
> first section, the tab has an outline and when moved to the next  
> section, the second tab has the outline

Would current\_page be of any help?

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![vagabond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/258eb7/32.png) [@vagabond](https://www.ruby-forum.com/u/vagabond)\
**Post date:** [July 3, 2009, 10:27am UTC](https://www.ruby-forum.com/t/tracking-website-sections/171475/3 "2009-07-03T10:27:08Z")

</div>

On Fri, Jul 3, 2009 at 9:51 AM, Marnen  
Laibow-Koser[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

I don’t think so because that seems to do a direct comparison (after  
splitting off query params)  
I would need something more generic

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)

[http://MyMvelope.com](http://MyMvelope.com) - The SIMPLE way to manage your savings

---

<div class="post-metadata">

**Author:** ![vagabond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/258eb7/32.png) [@vagabond](https://www.ruby-forum.com/u/vagabond)\
**Post date:** [July 4, 2009, 12:22am UTC](https://www.ruby-forum.com/t/tracking-website-sections/171475/4 "2009-07-04T00:22:30Z")

</div>

It’s probably not ideal, but I’ve used the simplest possible solution  
for this in some live code - just set an instance variable in the  
controller and refer to it in the view / layout where the menu is. You  
can even set the variable in a before\_filter if it is the same across  
all the actions in your controller.

Again, probably not the most “meta” solution available, but able to  
handle _any_ weird site layout you might have.

–Matt J.

On Jul 3, 12:56 am, Andrew T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
