Layout Problem: No page headers or footers!

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

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.

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.

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

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!

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.

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.

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?

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.

Plz explain me in detial, am new to RoR…