Rails Production server: stylesheets not displaying!
Asked Answered
U

1

12

I just switched over from my development database to the production database, and I realized I'm getting a consistent error nomatter what view I try to open. The stylesheets are not loading correctly, despite being in the correct place.

Here's some information about the error:

View

<head>
<%= stylesheet_link_tag "global", "home", "http://static.flowplayer.org/tools/css/scrollable-navig.css" %>
</head>

Console

Started GET "/stylesheets/global.css?1287048448" for 127.0.0.1 at 2010-10-15 00:18:43 -0400
Processing by WelcomeController#long_switchboard as CSS
Parameters: {"1287048448"=>nil, "path"=>"stylesheets", "link"=>"global"}
Completed   in 2ms

NoMethodError (undefined method `id' for nil:NilClass):
  app/controllers/welcome_controller.rb:76:in `long_switchboard'
Rendered C:/Sanj/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.0ms)
Rendered C:/Sanj/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (7.0ms)
Rendered C:/Sanj/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack3.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (108.0ms)

Page Source

<link href="/stylesheets/global.css?1287048448" media="screen" rel="stylesheet" type="text/css" />  
<link href="/stylesheets/home.css?1287086704" media="screen" rel="stylesheet" type="text/css" />  
<link href="http://static.flowplayer.org/tools/css/scrollable-navig.css" media="screen" rel="stylesheet" type="text/css" />    

When I try to open the 'global' and 'home' stylesheets from the page source, they are not opened. I tried adding 'public/' to the URL but it says no route matches.

Location

All non-http stylesheets are in root/public/stylesheets/

Routes

The last two routes are the 'catch-alls', only there for a particular feature on the site. These seem to be catching my stylesheets (and possibly other tags too).

match ':path/:link' => 'welcome#long_switchboard'  
match ':path' => 'welcome#short_switchboard'
Urease answered 15/10, 2010 at 4:34 Comment(4)
The routes page takes them into a catchall controller action at the bottom of my routes page, which my site uses as a feature for user convenience (users can create different urls for others to access). There's no 404 or 403 - instead I just get an ugly unformatted page!Urease
So the problem is in routes.rb... Make sure that /stylesheets, /images, /javascripts etc. are not caught by the 'catch-all' route. Post your routes.rb if you want suggestions how to fix this.Meadow
I've added the routes file, Tokyo. ThanksUrease
What webserver are you using?Meadow
M
18

This thread has some suggestions...

Depending on your webserver you may have to change the following setting in config/environments/prodcution.rb from:

config.serve_static_assets = false

To:

config.serve_static_assets = true
Meadow answered 15/10, 2010 at 5:15 Comment(1)
The comments above this line says > "Disable Rails's static asset server. In production, Apache or nginx will already do this" So should I turn it to false if i use nginx in production?Cherie

© 2022 - 2024 — McMap. All rights reserved.