Ruby on rails 3 未在Heroku/Thin上提供静态资产
我在Heroku上没有提供静态资产(图像、js和样式表)方面遇到了问题。 在我的本地开发环境中运行良好 错误如下所示:Ruby on rails 3 未在Heroku/Thin上提供静态资产,ruby-on-rails-3,heroku,thin,Ruby On Rails 3,Heroku,Thin,我在Heroku上没有提供静态资产(图像、js和样式表)方面遇到了问题。 在我的本地开发环境中运行良好 错误如下所示: 2011-08-08T02:58:45+00:00 app[web.1]: Started GET "/stylesheets/reset.css" for 98.234.235.21 at 2011-08-07 19:58:45 -0700 2011-08-08T02:58:45+00:00 app[web.1]: 2011-08-08T02:58:45+00:00 app
2011-08-08T02:58:45+00:00 app[web.1]: Started GET "/stylesheets/reset.css" for 98.234.235.21 at 2011-08-07 19:58:45 -0700
2011-08-08T02:58:45+00:00 app[web.1]:
2011-08-08T02:58:45+00:00 app[web.1]: ActionController::RoutingError (No route matches "/stylesheets/reset.css"):
我正在使用:
- Ruby 1.9.2
- Rails 3.0.7
- Heroku与Bambon-mri-1.9.2和瘦Web服务器。(我遵循heroku.com上的默认基本设置说明)
- 删除config.ru
- 将
添加到config.ru使用ActionDispatch::Static“#{Rails.root}/public”
- 在staging.rb中设置
config.service\u static\u assets=true
编辑: 提供js文件,但图像和样式表不提供。 我检查了链接中的路径是否一致
myapp.heroku.com/stylesheets/reset.css
-失败
myapp.heroku.com/javascripts/jquery.js
-成功
我还尝试设置以下内容:config.action\u dispatch.x\u sendfile\u header=nil
。
这与config.service\u static\u assets=true一起使用,但注意到Heroku强制执行这些选项,无论您如何设置它们。i、 e.在启动过程中执行以下操作:
-----> Detected Rails is not set to serve static_assets
Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile
Installing rails3_disable_x_sendfile... done
我不确定Heroku是否在暂存
环境中运行,我认为它是在生产
环境中运行的,这就是为什么没有应用您的设置。问题是资产文件没有推送到Heroku(我是git出错,不是Heroku问题)
Heroku的支持人员在我联系他们时指出了这一点。他们迅速作出了详细答复,其中还包括以下评论:
- Heroku gem不需要在Heroku上运行
- 在Gemfile中指定postgres gem;在本地使用postgres代替sqlite3进行开发
- config.ru:不要直接运行调度程序,请运行应用程序容器
- 不要将x_sendfile_头设置为nil,因为这在Rails 3上不受正确支持(这是Rails 3.1设置)
Ryan,我将其配置为运行暂存,并验证是否应用了我的更改:heroku config--remote staging
显示了RACK_ENV=>staging
和RAILS_ENV=>staging