Rails 3 引擎 &静态资产 [英] Rails 3 Engine & Static assets

查看:27
本文介绍了Rails 3 引擎 &静态资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个作为 gem (gmaps4rails) 捆绑的引擎.我将引擎的/public 复制到了 Rails 应用的/public 中.

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"):

我做了几件事:

  1. 在我的应用程序的 production.rb 中,我设置:

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

config.serve_static_assets = true

config.serve_static_assets = true

这解决了问题但不够优雅,我想将其设置为false并在引擎中添加配置:)

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

我遵循了此处的建议但没有成功.p>

I followed the advice here without success.

推荐答案

出于性能原因,静态资产服务在生产模式下被禁用.您的网络服务器应配置为提供这些资产.

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

看看这个讨论您正在使用 nginx 作为网络服务器.

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

这篇关于Rails 3 引擎 &静态资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆