Forum: Ruby on Rails render :partial in /app/views/layouts

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.
4500aa049300bec55b2e2d1f4c5b1290?d=identicon&s=25 Trevor Menagh (Guest)
on 2009-04-21 21:19
(Received via mailing list)
Hi all,

I have many layouts that apply to parts of my Rails site. Some of the
elements of each of the layouts are the same. I would like to create
something like a partial to use within layouts.

For example, I might have two layouts that have identical <head>
information, but different <body> formatting.

Is there a way to separate out the identical information so I can DRY
up my layout code? I didn't have much luck creating partials in the
layout directory.

Thanks,
trv
4500aa049300bec55b2e2d1f4c5b1290?d=identicon&s=25 Trevor Menagh (Guest)
on 2009-04-21 22:09
(Received via mailing list)
After doing some searching I found nested-layouts (http://github.com/
radar/nested-layouts/tree/master). It seems to do the trick, although
to get it to work with my Rails 2.3.2 app, I had to change part of
line 13 of lib/nested_layouts.rb from 'app/views/layouts' to "#
{RAILS_ROOT}/app/views/layouts"

If anyone has some better/alternative solutions, I am all ears.

trv
782b01570270ab10543bc25a258d7ea8?d=identicon&s=25 Dmitry Sokurenko (Guest)
on 2009-04-21 22:13
(Received via mailing list)
Actually partials in the layout directory work fine (like in any other
dir), but you need to specify the directory explicitly:

layouts/
  _head.html.erb
  application.html.erb

In application.html.erb
  <%= render :partial => 'layouts/head' %>

Dmitry
This topic is locked and can not be replied to.