Dynamic Menu and Session

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

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