导轨4支持导轨来提供静态资产:它是正确的吗? (在heroku上) [英] rails 4 enabled rails to serve static assets: is it correct? (on heroku)

查看:102
本文介绍了导轨4支持导轨来提供静态资产:它是正确的吗? (在heroku上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:heroku



Rails:4



Ruby:2



我们将一个应用程序部署到了heroku,并且好像公共文件夹中的任何内容都不可访问(没有看到静态文件,所以路由器启动后抱怨没有路由匹配)。



为了解决这个问题,我们设置了

pre code config.serve_static_assets =真正的

在我们的production.rb文件中。这真的是处理这个问题的最好方法吗?或者我们是否未能配置应用程序如何正确托管在heroku上?

在以前的Rails版本中,Heroku注入了一个插件,启用服务的静态资产,所以这个问题不存在。由于这个插件系统在Rails 4中被删除,他们现在创建了一个相同的gem。您可以通过以下方式在您的Gemfile中启用它:

  gem'rails_12factor',group :: production b $ b  

请参阅开始使用Rails 4 .x在Heroku上



您当然也可以为您的资产使用CDN,但您并不需要。


Environment: heroku

Rails: 4

Ruby: 2

We deployed an app to heroku, and it seemed as though anything in the public folder was not accessible (didn't see the static file so the router kicked in and then complains about no route matching).

To get around this, we set

config.serve_static_assets = true

in our production.rb file. Is this really the best way to handle this? Or did we fail to configure the app some how to be hosted on heroku properly?

解决方案

In previous Rails versions, Heroku injected a plugin that enabled serving of static assets so this issue didn't exist. As this plugin system was removed in Rails 4, they now created a gem which does the same. You enable it in your Gemfile via:

gem 'rails_12factor', group: :production

See Getting Started with Rails 4.x on Heroku

You could also of course use a CDN for your assets, but you're not required to.

这篇关于导轨4支持导轨来提供静态资产:它是正确的吗? (在heroku上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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