Rails 5无法在生产模式下加载资产(Rails 5 unable to load assets in production mode)

编程入门 行业动态 更新时间:2024-10-26 08:25:30
Rails 5无法在生产模式下加载资产(Rails 5 unable to load assets in production mode)

我能够在rails应用程序的公共/资产目录中预编译资产。 但是当我在生产中启动应用程序时,rails构建了错误的路径而没有指向预编译的资产。

系统环境详细信息如下。

rails -v Rails 5.0.4 ruby -v ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32] "sprockets-rails", '2.3.3'

和production.rb

# Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = true # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false

和asset.rb

# Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. Rails.application.config.assets.precompile += %w( *.js *.css *.js.erb *.css.erb)

而我的index.html.erb看起来就是这样

<%=javascript_include_tag "bootstrap.min"%> <%=stylesheet_link_tag "bootstrap.min"%>

和铁路试图使用以下路径获取资产,

并且文件夹中的编译资产看起来如下。

请帮我找出错误的地方。 在此先感谢,任何帮助表示赞赏。

I am able to precompile assets in public/assets directory of rails application. But when I start application in production, rails constructing wrong path and not pointing to the precompiled assets.

System environment details are as below.

rails -v Rails 5.0.4 ruby -v ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32] "sprockets-rails", '2.3.3'

and production.rb

# Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = true # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false

and asset.rb

# Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. Rails.application.config.assets.precompile += %w( *.js *.css *.js.erb *.css.erb)

And my index.html.erb looks this way

<%=javascript_include_tag "bootstrap.min"%> <%=stylesheet_link_tag "bootstrap.min"%>

and the rails trying to fetch assets using below paths,

and the compiled assets in folders looks as bellow.

Kindly help me to find out where I am going wrong. Thanks in advance and any help appreciated.

最满意答案

确保启用了摘要设置:

config.assets.digest = true

Make sure the digest setting is enabled:

config.assets.digest = true

更多推荐

本文发布于:2023-08-07 05:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1460828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   资产   模式下   Rails   unable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!