Rails3程序在产品模式下出现assert文件404错误的问题

rails3程序部署产品模式之后
出现以下静态文件错误

17:14:26 INFO: Started GET "/assets/application-b42d228d39a3e30c7479d7bf2fd1709b.js" for 10.0.2.2 at 2013-03-07 17:14:26 +0800
17:14:26 FATAL:
ActionController::RoutingError (No route matches [GET] "/assets/application-b42d228d39a3e30c7479d7bf2fd1709b.js"):
actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.9) lib/rails/rack/logger.rb:18:in `call'


这个问题看上去像是assert资源的问题,首先要确保下面这个命令运行,编译静态文件

bundle exec rake assets:precompile


我上面处先的问题是在这一步之后,我的启动方式,是
rails s

开发模式样式表,js什么的都有,但是产品模式下就是上面那个问题了。

原因在下面:
# config/environments/production.rb
...
config.serve_static_assets = false
...


上面是产品模式的配置,开发模式默认是没有这个选项的。

解决方案有两种:
方法一:是把上面那一行配置改成 true
方法二:是搭建nginx或者apache服务器,ngxin和apache会直接读取静态文件,不会产生这个问题

这是来自stackoverflow上的答案
[quote]
In production mode, Rails will not be responsible for serving static assets. Therefore, you are getting this error. Thin won't do it either, since it's just a wrapper around Rails.

This is controlled by this setting in config/environment/production.rb in your application:

config.serve_static_assets = false
You can either set to that true or use a real server like Apache or Nginx which will serve the static assets. I suspect Pow may also do it.

share|improve this answer
[/quote]
其访问地址[url]http://stackoverflow.com/questions/7829480/no-route-matches-get-assets[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值