DRY question (newbie)

Say i want to include the same chunck of text (a menu on a webpage for
example) on each page. Is there a method by which I can save the HTML in
a text file and call it up later? Is there a better way?

I know ruby has “puts” but i can’t use that b/c it does not work with my
webhost (dreamhost.com)

Any suggestions?

For a menu you would usually put that in a layout, then in your
controllers
you can specify that layout using…

layout “mylayout”

Inside your layout you would do something like…

...head stuff... ...menu bar html... <%= yield %>

The <%= yield%> line puts what would usually be appearing without a
layout
in its place.

Good Luck!

~Jamie
www.jamiequint.com
[email protected]

If you want the menu system to be available to your entire application,
put
it in /app/views/layouts/application.rhtml. It will automatiaclly be
used by
all controllers without having to use the layout command at the top of
each
controller.

For something like a nav, that will appear on all pages, a layout is
what you want to use, like Jamie mentioned.

If you have a chunk of html that will be used on some pages, but not
all, look into using a partial.

-TJ

You want layouts…

Create ./app/views/layouts/application.rhtml

Try something like


Hello World from the header!
<%= @content_for_layout %>
Hello world form the footer!


On 7/25/06, Daniel N [email protected] wrote:

Cheers

I probably should add that this method is only really useful when the
menu
changes per view.

Otherwise as others have suggested, stick it in the layout or a partial.

On 7/25/06, Stephen [email protected] wrote:

Hello world form the footer!

example) on each page. Is there a method by which I can save the HTML in

[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Another alternative to this is to use the content_for method

In you view

<% content_for( “menu”) do %>
erb for menu here
<% end %>

and then in your layout

<%= yield :menu %>

This should put your menu code in. If it’s not right I’ll check then
syntax when I get home

Cheers

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs