[英]Rails assets are in a sub directory and cannot load in production
Currently my event CSS is in app/assets/stylesheets/pages/events.scss
and in development mode it looks fine and the assets are loaded. 目前,我的事件CSS位于app/assets/stylesheets/pages/events.scss
,在开发模式下,它看起来不错,并且已加载资产。 But on production, it looks like these pages are not loaded at all. 但是在生产中,这些页面看起来根本没有加载。 I'm not sure how to fix this problem. 我不确定如何解决此问题。 I've looked at Rails 4: assets not loading in production but I am not familiar with the config.assets.precompile += %w( *.js ^[^_]*.css *.css.erb)
since it seems like the path itself is not working in production. 我看过Rails 4:资产未在生产中加载,但我对config.assets.precompile += %w( *.js ^[^_]*.css *.css.erb)
并不熟悉就像路径本身在生产中不起作用一样。
app/assets/stylesheets/application.scss: 应用程序/资产/样式表/application.scss:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
*#= require bootstrap-wysihtml5
*#= require rails_bootstrap_forms
*#= require jquery.jcrop
*= require custom
*= require_self
*/
@import "bootstrap-sprockets";
@import "bootstrap";
@import "scaffolds";
app/views/events/index.html.erb: app / views / events / index.html.erb:
<% content_for :head do %>
<%= stylesheet_link_tag "pages/events", :media => "all" %>
<% end %>
app/assets/stylesheets/pages/events.scss 应用程序/资产/样式表/页面/events.scss
@import "globals/helpers";
@import "vendors/animate";
.events-bar {
/* a[class*="btn"] {
height: 36px;
display: inline-block;
}*/
#toggleBar {
margin-top: 14px;
}
.btn-dashboard {
background-color: #fdf9ff;
color: $eventsColour !important;
&:hover {
background-color: $eventsColour-dark !important;
}
}
}
It's been hard to debug since it works fine in development and not in production. 调试起来很困难,因为它在开发中而不是在生产中都可以正常工作。 It looks like that all of the files in subdirectory (app/assets/stylesheet/pages/*.scss) are not working in production. 子目录(app / assets / stylesheet / pages / *。scss)中的所有文件似乎都无法在生产中使用。 Any insight will help, thanks. 任何见解都会有所帮助,谢谢。
You just need to add events to your precompile assets list since its not compiled with application.scss
the format you want is 您只需将事件添加到预编译资产列表中,因为它未使用application.scss
进行编译,所需格式为
config.assets.precompile += %w( pages/events.scss )
then 然后
bundle exec rake assets:precompile
In your application.scss, you should add: 在application.scss中,应添加:
*= require pages/events
run bundle exec rake assets:precompile
运行bundle exec rake assets:precompile
Let me know if it fixes the error or if it doesn't what error messages? 让我知道它是否解决了错误或是否没有什么错误消息?
I had same issue on Rails version - 5.2.3
我在Rails version - 5.2.3
上有相同的问题Rails version - 5.2.3
Asset file located as- 资产文件位于-
app/assets/images/sub-folder
add all images were in
sub-folder
but was not loading on production whereas working fine on local. 添加所有图像都在sub-folder
但未在生产环境中加载 ,而在本地运行良好。
image location in css- 图片位置在CSS-
url(./sub-folder/b2.jpg)
Here is what I did- 这是我所做的-
in /config/environments/production.rb
set- 在/config/environments/production.rb
设置
config.assets.compile = true
Initially it was false
, I just pushed code on server and everything found working as desired! 最初是false
,我只是在服务器上推送了代码,发现所有内容都按需运行!
hope will work for you too!!! 希望也能为您服务!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.