Common menu


#1

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


#2

Fab

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

Alain


#3

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" %>
<%= @page_title || "GP-matic Bookshelf" %>
Home
Questions
News
Contact
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' %>
 
<% 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


“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!