Forum: Ruby on Rails Common menu

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Fab P. (Guest)
on 2005-12-24 13:47
(Received via mailing list)

    I'm releasing my first rails application and I'd like to have a
menu in all my templates.
Do I have to include an rhtml from .rb or other rhtml ? Some sample code

Alain R. (Guest)
on 2005-12-24 14:08

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

Gerard (Guest)
on 2005-12-24 14:23
(Received via mailing list)
Hi Fab,

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

  <title>Prag Prog Books Online Store</title>
  <%= stylesheet_link_tag "depot", :media => "all" %>
  <div id="banner">
    <img src="/images/gp_canv_logo.jpg">
    <%= @page_title || "GP-matic Bookshelf" %>
  <div id="columns">
    <div id="side">
      <a href="http://...">Home</a><br/>
      <a href="http://...">Questions</a><br/>
      <a href="http://...">News</a><br/>
      <a href="http://...">Contact</a><br/>
      <a href="/admin">Admin</a><br/>
    <div id="main">
      <% if @flash[:notice] -%>
        <div id="notice"><%= @flash[:notice] %></div>
      <% 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
your views you do not put any site or menu layout kind thingies (they go
layouts). Views only generate html output containing your actual html
encapsulated data, e.g.

<% for product in @products %>
  <div class="catalogentry">
	<table border="0"><tr><td width="100" valign="top">
	<img src="<%= product.image_url %>"/>
	</td><td valign="top">
	<h3><%=h product.title %></h3>
	<% product.description %>
	<span class="catalogprice"><%= number_to_currency(product.price)
  <%= link_to 'Add to Cart',
	{:action	=> 'add_to_cart', :id => product },
	:class => 'addtocart'	%><br/>
	<div class="separator">&nbsp;</div>
<% end %>

Hope it helps.


On Saturday 24 December 2005 12:45, Fab P. tried to type something
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid

"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
This topic is locked and can not be replied to.