Forum: Ruby on Rails Common menu

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fab P. (Guest)
on 2005-12-24 13:47
(Received via mailing list)
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
Alain R. (Guest)
on 2005-12-24 14:08
Fab

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

Alain
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
rhtml
file with the general site layout. And a name related to the controller.
e.g.
"store".

<html>
<head>
  <title>Prag Prog Books Online Store</title>
  <%= stylesheet_link_tag "depot", :media => "all" %>
</head>
<body>
  <div id="banner">
    <img src="/images/gp_canv_logo.jpg">
    <%= @page_title || "GP-matic Bookshelf" %>
  </div>
  <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>
    <div id="main">
      <% if @flash[:notice] -%>
        <div id="notice"><%= @flash[:notice] %></div>
      <% end %>
      <%= @content_for_layout %>			<<<
    </div>
  </div>
</body>
</html>

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 %>
  <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)
%></span><br/><br
/>
  <%= link_to 'Add to Cart',
	{:action	=> 'add_to_cart', :id => product },
	:class => 'addtocart'	%><br/>
	</td></tr></table>
	</div>
	<div class="separator">&nbsp;</div>
<% 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!
This topic is locked and can not be replied to.