Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Engine & Static assets

I'm building an engine I've bundled as a gem (gmaps4rails). I copied the /public of my engine in the /public of my rails app.

Everything works fine in development but fails to work in production: it appears static assets (of my engine & my main app) aren't found.

The logs tell the following (just an abstract):

Started GET "/javascripts/application.js?1286294679" for 127.0.0.1 at Wed Nov 24 00:22:20 +0100 2010

ActionController::RoutingError (No route matches "/javascripts/application.js"):


Rendered /Users/me/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/gems/1.8/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.1ms)


Started GET "/stylesheets/gmaps4rails.css?1290554221" for 127.0.0.1 at Wed Nov 24 00:22:20 +0100 2010

ActionController::RoutingError (No route matches "/stylesheets/gmaps4rails.css"):

I've done a few things:

  1. in my app's production.rb, I set:

    config.serve_static_assets = true

    This Solves the problem but is not elegant enough, I'd like to keep it to false and add configuration in the engine :)

  2. I followed the advice here without success.

like image 270
apneadiving Avatar asked Nov 24 '10 11:11

apneadiving


2 Answers

For performance reason, static assets serving is disabled in production mode. Your webserver should be configured to serve theses assets.

Look at this discussion if your are using nginx as a webserver.

like image 170
plang Avatar answered Nov 08 '22 22:11

plang


In Rails 3.x try to set this in config/environments/production.rb

config.serve_static_assets = true

By default Rails assumes you are using an assets server (lightttp, nginx or Apache)

like image 31
Juanin Avatar answered Nov 09 '22 00:11

Juanin