没有路由匹配 [GET]/assets [英] No route matches [GET] /assets

查看:25
本文介绍了没有路由匹配 [GET]/assets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Rails 应用程序,我想在生产环境中测试它.我运行了 RAILS_ENV=production rake assets:precompile,它在/public/assets 中生成了我的所有资产.问题是,当我使用 RAILS_ENV=production rails s Thin 启动我的应用程序时,我得到:

I have a Rails app that I'm trying to test in the production environment. I ran RAILS_ENV=production rake assets:precompile which generated all of my assets in /public/assets. The problem is that when I start my app w/ RAILS_ENV=production rails s thin I get:

ActionController::RoutingError (No route matches [GET] "/assets/application-eff78fd67423795a7be3aa21512f0bd2.css"):

这个文件确实存在于 /public/assets/application-eff78fd67423795a7be3aa21512f0bd2.css.

This file does exist though at /public/assets/application-eff78fd67423795a7be3aa21512f0bd2.css.

有没有想过为什么我会收到这个 RoutingError?

Any thoughts as to why I'm getting this RoutingError?

推荐答案

在生产模式下,Rails 将不负责提供静态资产.因此,您收到此错误.Thin 也不会这样做,因为它只是 Rails 的包装.

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.

这由应用程序中 config/environments/production.rb 中的此设置控制:

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

config.serve_static_files = false

或者在 Rails 5 中:

Or in Rails 5:

# config/environments/production.rb
config.public_file_server.enabled = true

或者将 ENV['RAILS_SERVE_STATIC_FILES'] 设置为 true.

Or set ENV['RAILS_SERVE_STATIC_FILES'] to true.

您可以设置为 true 或使用真正的服务器,如 Apache 或 Nginx,它将为静态资产提供服务.我怀疑 Pow 也可能这样做.

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.

如果您使用 Heroku,他们建议使用 rails_12factor gem,它默认启用此设置.将 gem 放入 Gemfile 中的 production 组,如下所示:

If you're on Heroku, they recommend the use of the rails_12factor gem which enables this setting by default. Place the gem into a production group in your Gemfile, like this:

group :production do
  gem 'rails_12factor'
end

这篇关于没有路由匹配 [GET]/assets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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