# Layout Problem: No page headers or footers!

**URL:** <https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850>\
**Category:** Rails\
**Created:** [October 21, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850 "2007-10-21T15:22:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![f212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb9ed0/32.png) [@f212](https://www.ruby-forum.com/u/f212)\
**Post date:** [October 21, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850/1 "2007-10-21T15:22:57Z")

</div>

Noob here. Been walking through the depot example in AWDWR second  
edition and discovered when I tried to add styling I found that my  
pages were not being wrapped by the layout template: They had no  
headers or footers, hence no css declaration, hence no styling. The  
body appears in my browser just fine.

What’s going on here?

My specifics are that I’m running on Mac OS X 10.4.10, with a RoR  
install verbatim from

> **[Dan Benjamin](https://danbenjamin.com)**
>
> Dan Benjamin's personal website.

Essentially Ruby 1.8.6, Gems 0.9.2, and a Rails install from gems done  
last week. The code I’m using for the depot is downloaded directly  
from the AWDWR site and includes:

- 003\_add\_test\_data.rb
- the images on the site
- admin.rhtml
- depot.css
- list.rhtml

Did I miss something? Do I need to set a switch or something? My code  
seems to be falling into the right places, so I’m kind of at a loss  
for what’s going on.

---

<div class="post-metadata">

**Author:** ![f212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb9ed0/32.png) [@f212](https://www.ruby-forum.com/u/f212)\
**Post date:** [October 21, 2007, 3:29pm UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850/2 "2007-10-21T15:29:22Z")

</div>

Add an application.rhtml (or application.hthl.erb if you’re on 2.0  
PR), and add stuff there. Insert a \<%= yield % \> where you want the  
contents to appear.

---

<div class="post-metadata">

**Author:** ![f212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb9ed0/32.png) [@f212](https://www.ruby-forum.com/u/f212)\
**Post date:** [October 21, 2007, 5:30pm UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850/3 "2007-10-21T17:30:38Z")

</div>

Assuming the layout [with the headers and footers] is in admin.rhtml,  
you’ll want to make sure you use

```
layout "admin"

```

in yr controller. Or do as August suggests and just rename admin.rhtml  
to application.rhtml and the layout will load automatically.

RSL

---

<div class="post-metadata">

**Author:** ![f212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb9ed0/32.png) [@f212](https://www.ruby-forum.com/u/f212)\
**Post date:** [October 21, 2007, 5:47pm UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850/4 "2007-10-21T17:47:00Z")

</div>

Thanks for the quick reply, August. Much appreciated.

Do you mean place a file named “application.rhtml” with the  
appropriate header and footer and \<%= yield % \> into the app/views/  
layouts directory? I already have have a .rhtml with the same prefix  
as my controller sitting in the app/views/layouts directory. If I need  
a file named “application.rhtml”, why didn’t rails generate that? Did  
I miss a step?

FYI, my setup looks like the following: As per the AWDWR depot  
example, the critical component is admin, and I have an…

- admin\_controller.rb in the controllers dir
- admin directory in app/views that contains list.rhtml
- admin.rhtml in app/views/layouts

My directory structure looks like this:

app  
controllers  
admin\_controller.rb  
application.rb  
helpers  
models  
views  
admin  
\_form.rhtml  
edit.rhtml  
list.rhtml  
new.rhtml  
show.rhtml  
layouts  
admin.rtml  
components  
config  
etc…

My admin.rhtml in app/views/layouts looks like this:

* * *
 Admin: \<%= controller.action\_name %\> \<%= stylesheet\_link\_tag 'scaffold' %\>

\<%= flash[:notice] %\>

\<%= yield :layout %\>

------------------------------------------------------------------------------------------

I also tried simply \<%= yield % \> in the .rhtml above. No difference  
in the outcome.

Again, thanks in advance for any help!

---

<div class="post-metadata">

**Author:** ![f212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb9ed0/32.png) [@f212](https://www.ruby-forum.com/u/f212)\
**Post date:** [October 21, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850/5 "2007-10-21T18:12:10Z")

</div>

Russell,

We crossed posts. My response above was to August.

I just tried your suggestions, changing admin.rhtml to  
application.rhtml and using layout “admin” in the controller. Neither  
solved the problem.

Don’t know what the issue is with changing admin.rhtml to  
application.rhtml, but I bet the issue with the layout “admin”  
solution is that, since I’m a noob, I don’t know where in the  
controller (I’m guessing the admin controller) the line would go.  
Additionally, I doubt my syntax is correct. What I did was, within  
admin\_controller.rb, I changed

…  
def list  
@product\_pages, @products = paginate :products, :per\_page =\> 10  
end  
…

to

…  
def list  
layout “admin”  
@product\_pages, @products = paginate :products, :per\_page =\> 10  
end  
…

Sorry if I wasn’t to take things so literal, Russell, but since I  
don’t know ruby yet, I gotta take everything at face value.

thx y’all, and any further help would be really nice. Further insight  
into why the application.rhtml solution isn’t working would be great  
too. In fact, the problem with application.rhtml may be a clue to the  
problem with everything.

---

<div class="post-metadata">

**Author:** ![f212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb9ed0/32.png) [@f212](https://www.ruby-forum.com/u/f212)\
**Post date:** [October 21, 2007, 8:42pm UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850/6 "2007-10-21T20:42:32Z")

</div>

Do you have a file called app/views/layouts/application.rhtml? If so,  
make sure you do not have a call to the layout method in your controller  
(like layout :scaffold).

-Bill

f212 wrote:

> Did anyone else do a clean install last week?
> 
> >

–

Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![f212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb9ed0/32.png) [@f212](https://www.ruby-forum.com/u/f212)\
**Post date:** [October 21, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850/7 "2007-10-21T20:00:26Z")

</div>

A further note…

Just added a new page (the AWDWR store index on page 97), and it  
doesn’t get wrapped with headers or footers either. Rails finds the  
page, parses the rhtml, and sends it to the browser, but the layout  
nesting is just plain missing. Could the version of Rails I’m using be  
buggy?

(I doubt it, but something’s very fishy here.)

Did anyone else do a clean install last week?

---

<div class="post-metadata">

**Author:** ![f212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb9ed0/32.png) [@f212](https://www.ruby-forum.com/u/f212)\
**Post date:** [October 22, 2007, 12:56am UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850/8 "2007-10-22T00:56:29Z")

</div>

FIGURED IT OUT!

And it was none of the above. What it was was that my initial setup  
for the depot app also installed rubyAMF, with the thought that I  
could experiment with some FlexRailing at a later point.

Don’t know if you’ve all chatted about this and it’s old news, but for  
a noob like me, I found it pretty odd. For some reason

> > > RubyAMF forces Rails to ignore layouts!\<\<\<

There you have it.

---

<div class="post-metadata">

**Author:** ![f212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb9ed0/32.png) [@f212](https://www.ruby-forum.com/u/f212)\
**Post date:** [December 6, 2007, 12:49pm UTC](https://www.ruby-forum.com/t/layout-problem-no-page-headers-or-footers/117850/9 "2007-12-06T12:49:06Z")

</div>

Plz explain me in detial, am new to RoR…
