Layout antics


#1

I have a strange problem with my layout file. I think it may be due to
nested partials, but removing the deepest nested partial call does not
clear the problem.

I have an application wide layout (application.html.erb) that works as
expected - loads images, javascript, css etc for my application.

So http://localhost:3000/patients --> fine
http://localhost:3000/patients/new --> fine
http://localhost:3000/operations --> fine
http://localhost:3000/operations/new --> problems

The problem is that rails is suddenly confused about paths and
interprets:

<link href=“css/menu.css” rel=“stylesheet” type=“text/css” />

As routing calls. (from the stderror output):

Processing OperationsController#css to css (for 127.0.0.1 at
2009-05-01 06:07:26) [GET]
Parameters: {“id”=>“menu”}

ActionController::UnknownAction (No action responded to css. Actions:
access_denied, check_group, check_roles, create, destroy, edit, index,
new, role_requirements, role_requirements=, show, toggle, and update):

Does anyone have an idea of where to look or have you seen this error
before?

Nothing dynamic is changing in the layout file to my knowledge. This
error occurs if I call that page directly, or if I get there through
the application (operations belong to patients, patients have many
operations).


#2

dwormuth wrote:

http://localhost:3000/operations/new --> problems

The problem is that rails is suddenly confused about paths and
interprets:

<link href=“css/menu.css” rel=“stylesheet” type=“text/css” />

I’d try using an absolute path i.e: “/css/menu.css”

HTH

~Matt


#3

Matt H. wrote:
[…]

I’d try using an absolute path i.e: “/css/menu.css”

HTH

~Matt

Better yet, use stylesheet_link_tag – that way Rails will construct the
proper path and save you some typing.

Best,

Marnen Laibow-Koser
http://www.marnen.org
removed_email_address@domain.invalid


#4

dwormuth wrote:
[…]

I’d really like to understand why the layout works for some
controller/actions and not for others.

Most likely because you had a relative URL that worked with respect to
/operations, but not with respect to /operations/new (which is one level
deeper in the virtual directory hierarchy that Rails creates). Notice
that the absolute path for your CSS file works in all cases.

This is fundamental to all Web development. If you don’t understand the
difference between absolute and relative paths, then go study some more,
because it’s essential that you understand it. If you do understand
it, then be aware that it works in Rails the same as it does anywhere
else (except that most of the directories are virtual).

Does that help?

Best,

Marnen Laibow-Koser
http://www.marnen.org
removed_email_address@domain.invalid


#5

The hard coded url fixed the problem. I’ll try the stylesheet_link tag
next. I’d really like to understand why the layout works for some
controller/actions and not for others.

Thanks for the help

Dave

On May 1, 12:43 pm, Marnen Laibow-Koser <rails-mailing-l…@andreas-


#6

Thanks, I was considering “new” as the same level as “index”, but see
how this makes a difference.

Dave

On May 2, 4:01 am, Marnen Laibow-Koser <rails-mailing-l…@andreas-