资产预编译确定,但尝试获取文件时为404
好的,所以编译我的资产工作正常,但当我运行时:
thin start -e production
没有我的javascript或css正在加载。 我的浏览器也取消了获取资产的请求。 我不确定为什么会这样,但我怀疑它是因为它认为它是404’。 如果您查看顶部图像,您将看到我的application.css文件已编译并存储在我的assets文件夹中,但当我尝试访问该文件时,我收到了我的404.html文件。
是什么赋予了!?
编辑:
我被要求发表我的观点。 以下是项目中的一些代码:
Quick Quote
我的布局:
"all" %>
我的production.rb中的代码
config.assets.precompile += %w( quote.css jquery-ui-timepicker-addon.css prices.css contact.css )
我的application.css.scss.erb的顶部:
/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the top of the * compiled file, but it's generally better to create a new file per style scope. * *= require_self * * require_tree . <- commented out * require jquery-ui-timepicker-addon.css <- commented out */
我的整个application.js文件
// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // //= require jquery //= require jquery_ujs //= require jquery-ui //= require jquery-ui-timepicker-addon.js //= require_tree .
检查你的config/environments/production.rb
文件并添加下一行(如果它还没有):
config.serve_static_assets = true
Rails建议默认情况下应禁用此设置config.serve_static_assets
,即设置为false。 以下是rails app中生成的config/environments/production.rb
的默认配置
禁用Rails的静态资产服务器(Apache或nginx已经这样做了)
config.serve_static_assets = false
因此,如果您在本地应用程序中将其设置为true
,那么这仍然很好。 但是,如果您在Apache或ngix或heroku以外的任何其他设备上部署应用程序,则不建议在您的production.rb
配置文件中production.rb
config.serve_static_assets=true
。 这是Rails指南中的文档。
config.serve_static_files配置Rails本身以提供静态文件。 默认为true,但在生产环境中关闭,因为用于运行应用程序的服务器软件(例如NGINX或Apache)应该为静态资产提供服务。 与默认设置不同,在运行时(绝对不推荐!)或使用WEBrick在生产模式下测试应用程序时将此设置为true。 否则,您将无法使用页面缓存,并且对公共目录下经常存在的文件的请求将无论如何都会打到您的Rails应用程序。
你能把这一行放在你当前的环境中吗.rb?
config.serve_static_assets=true
参考: 这里
- Rails ORM是否限制执行聚合的能力?
- Rails 4.1将秘密推向heroku
- 之前(:上下文)确定范围是否适用于儿童情境?
- Rails中的动态选择菜单/级联下拉?
- 为什么不/ do和{}总是等价?
- Rails和Postgres Hstore:你能在迁移中添加索引吗?
- 如何使用Rails ActiveRecord进行LEFT OUTER JOIN?
- rails生成rspec:install config / environments / development.rb:1:在`’:undefined method`configure’
- 如何正确地将record.image_integrity_error添加到现有条件?