Common menu

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Common menu

fabf
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


_______________________________________________
Rails mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails
Reply | Threaded
Open this post in threaded view
|

Re: Common menu

Alain Ravet-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

--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Rails mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails
Reply | Threaded
Open this post in threaded view
|

Re: Common menu

Gerard Petersen
In reply to this post by fabf
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 Psycho tried to type something like:

> 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
>
>
> _______________________________________________
> Rails mailing list
> [hidden email]
> 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!



_______________________________________________
Rails mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails