# Need help for dynamic menus

**URL:** <https://www.ruby-forum.com/t/need-help-for-dynamic-menus/93198>\
**Category:** Rails\
**Created:** [April 29, 2007, 4:04am UTC](https://www.ruby-forum.com/t/need-help-for-dynamic-menus/93198 "2007-04-29T04:04:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@rmehta](https://www.ruby-forum.com/u/rmehta)\
**Post date:** [April 29, 2007, 4:04am UTC](https://www.ruby-forum.com/t/need-help-for-dynamic-menus/93198/1 "2007-04-29T04:04:49Z")

</div>

Hi,

I need to generate dynamic menus and those menus items need to be picked  
from the database based on the role of the person logged in. Has anybody  
done anything similar to it? Any help and guidance is greatly  
appreciated.

Thanks.

---

<div class="post-metadata">

**Author:** ![rmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@rmehta](https://www.ruby-forum.com/u/rmehta)\
**Post date:** [April 29, 2007, 3:16pm UTC](https://www.ruby-forum.com/t/need-help-for-dynamic-menus/93198/2 "2007-04-29T15:16:57Z")

</div>

By dynamic menus, I assume you mean you want a navbar or something in  
the layout to change based on the context of a user’s session. So, you  
may have different tools associated with each page, right?

Assuming we’re on the right track, I’d explore using the flash system  
for something like that. So, you could set your flash[:navbar] to  
something in your application controller, and then override it where  
you would like to have it work differently in other controllers.

Also, I found this helpful in Scott R.'s Ajax on Rails book. He  
puts a simple method in his application\_helper.rb:

def flash\_div \*keys  
divs = keys.select { |k| flash[k] }.collect do |k|  
content\_tag :div, flash[k], :class =\> “flash #{k}”  
end  
divs.join  
end

Cheers,
