# Common menu

**URL:** <https://www.ruby-forum.com/t/common-menu/75110>\
**Category:** Rails\
**Created:** [December 24, 2005, 12:47pm UTC](https://www.ruby-forum.com/t/common-menu/75110 "2005-12-24T12:47:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fab\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@Fab\_P](https://www.ruby-forum.com/u/Fab_P)\
**Post date:** [December 24, 2005, 12:47pm UTC](https://www.ruby-forum.com/t/common-menu/75110/1 "2005-12-24T12:47:38Z")

</div>

Hi,

```
I'm releasing my first rails application and I'd like to have a 

```

common  
menu in all my templates.  
Do I have to include an rhtml from .rb or other rhtml ? Some sample code  
pls  
?

Regards,  
Fabian

---

<div class="post-metadata">

**Author:** ![Fab\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@Fab\_P](https://www.ruby-forum.com/u/Fab_P)\
**Post date:** [December 24, 2005, 1:08pm UTC](https://www.ruby-forum.com/t/common-menu/75110/2 "2005-12-24T13:08:58Z")

</div>

Fab

Extract the common html parts - including the menu - to a layout named  
“application.rhml”  
, and it will wrap around all your templates.

Alain

---

<div class="post-metadata">

**Author:** ![Fab\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@Fab\_P](https://www.ruby-forum.com/u/Fab_P)\
**Post date:** [December 24, 2005, 1:23pm UTC](https://www.ruby-forum.com/t/common-menu/75110/3 "2005-12-24T13:23:40Z")

</div>

Hi Fab,

An example (from the agile dev book) … In app/views/layouts you put a  
rhtml  
file with the general site layout. And a name related to the controller.  
e.g.  
“store”.

 Prag Prog Books Online Store \<%= stylesheet\_link\_tag "depot", :media =\> "all" %\> 
 ![](https://www.ruby-forum.com/images/gp_canv_logo.jpg) \<%= @page\_title || "GP-matic Bookshelf" %\> 

[Home](http://...)  
[Questions](http://...)  
[News](http://...)  
[Contact](http://...)  
[Admin](https://www.ruby-forum.com/admin)  

 \<% if @flash[:notice] -%\> 
\<%= @flash[:notice] %\>
 \<% end %\> \<%= @content\_for\_layout %\> \<\<\< 

The magical line in this template is \<%= @content\_for\_layout %\> is  
picked up  
from any store/filename.rhtml.

The views, in this case, under store all have that layout. So generally  
in  
your views you do not put any site or menu layout kind thingies (they go  
in  
layouts). Views only generate html output containing your actual html  
encapsulated data, e.g.

\<% for product in @products %\>

| ![]() | 
### \<%=h product.title %\>
 \<% product.description %\> \<%= number\_to\_currency(product.price) %\>  
  
 \<%= link\_to 'Add to Cart', {:action =\> 'add\_to\_cart', :id =\> product }, :class =\> 'addtocart' %\>  
 |

&nbsp;
\<% end %\>

Hope it helps.

Gerard.

On Saturday 24 December 2005 12:45, Fab P. tried to type something  
like:

> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
“Who cares if it doesn’t do anything? It was made with our new  
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;  
~  
:wq!
