Forum: Ruby on Rails Layout antics

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.
1e54a6e4b02cb09900868728f8cb25d0?d=identicon&s=25 dwormuth (Guest)
on 2009-05-01 12:29
(Received via mailing list)
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).
8fa0f5c2bf8ad238baa4e20cb0360ebd?d=identicon&s=25 Matt Harrison (iwasinnamuknow)
on 2009-05-01 18:20
(Received via mailing list)
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
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-05-01 18:43
Matt Harrison 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
marnen@marnen.org
1e54a6e4b02cb09900868728f8cb25d0?d=identicon&s=25 dwormuth (Guest)
on 2009-05-02 00:06
(Received via mailing list)
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-
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-05-02 10:01
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
marnen@marnen.org
1e54a6e4b02cb09900868728f8cb25d0?d=identicon&s=25 dwormuth (Guest)
on 2009-05-02 18:53
(Received via mailing list)
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-
This topic is locked and can not be replied to.