# Dynamic Menu and Session

**URL:** <https://www.ruby-forum.com/t/dynamic-menu-and-session/145682>\
**Category:** Rails\
**Created:** [August 12, 2008, 9:50pm UTC](https://www.ruby-forum.com/t/dynamic-menu-and-session/145682 "2008-08-12T21:50:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@Glen](https://www.ruby-forum.com/u/Glen)\
**Post date:** [August 12, 2008, 9:50pm UTC](https://www.ruby-forum.com/t/dynamic-menu-and-session/145682/1 "2008-08-12T21:50:20Z")

</div>

Hi,

I am trying to implement dynamic database-driven menu on my web  
application. Menu is just a set of links to controller actions, but  
each user has different set of menu items based on their privileges.  
Menu items (labels and URLs) are stored in database as ActiveRecord  
object called Menu.

The only problem is whenever browser is refreshed, it runs query to  
pull out menu items. This would be performance overhead. Menu items  
are not changed that often, so I am thinking it is better to put this  
kind of information to session variable.

I would like to know if this approach is a good direction. If so, in  
what format should I store menu item information, e.g., string, hash,  
or activerecord object?

Thanks in advance.

Glen

---

<div class="post-metadata">

**Author:** ![Glen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@Glen](https://www.ruby-forum.com/u/Glen)\
**Post date:** [August 13, 2008, 12:12am UTC](https://www.ruby-forum.com/t/dynamic-menu-and-session/145682/2 "2008-08-13T00:12:07Z")

</div>

Glen wrote:

> I would like to know if this approach is a good direction. If so, in  
> what format should I store menu item information, e.g., string, hash,  
> or activerecord object?

Hi Glen,

My menu has different sections based on the roles of the current user.  
It’s a sport schedule management application, so there are roles for  
players, coaches, referees, parents, and administrators. The entire menu  
structure is a collection of hashes and arrays, some of which get built  
dynamically. It has to get redrawn on every full page load, and I  
control access to the various sections via session variables. As the  
expands/collapses menu options, I store in session which ones are open  
so when the menu gets redrawn from page to page, it stays the same. In  
order to accomplish that, I have a small ajax call that updates the menu  
state in the session.

Peace,  
Phillip
