简体   繁体   English

Rails资产位于子目录中,无法在生产中加载

[英]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.

相关问题 Ruby on Rails-/ stylesheet目录中的样式表而不是/ assets中的样式表,生产中没有指纹 - Ruby on Rails - Stylesheets in /stylesheet directory and not in /assets, no fingerprint in production 无法使用 Rails 6 在生产中加载资产资源(css + js) - Can't load assets ressources (css + js) in production with Rails 6 Rails资产没有预编译,css在生产中看起来不同 - Rails assets not precompiling, css looks different in production 无法从 rails 中的 vendor 文件夹加载资产 - Not able to load the assets from the vendor folder in rails Rails 3-从开发到生产的转变-公共资产404 - Rails 3 - Moving from Development to Production - Public Assets 404 Rails 5,Sass :: SyntaxError无法预编译资产 - Rails 5, Sass::SyntaxError cannot precompile assets 生产中的Rails应用程序不会加载图像吗? - Rails app in Production doesn't load images? Rails在生产页面加载中复制资产? - Rails duplicating asset in production page load? 将twitter bootstrap主题安装到Rails 4应用中-找不到供应商/资产目录? - Install twitter bootstrap theme into rails 4 app - Vendor/assets directory not found? 在 Rails 中高效加载 CSS 和 JS(“为所有静态资产使用 CDN”) - Load CSS and JS efficiently in Rails ("Use a CDN for all static assets")
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM