gpt4 book ai didi

ruby-on-rails - Rails 应用程序未在生产环境中使用预编译 Assets

转载 作者:行者123 更新时间:2023-12-04 05:56:00 25 4
gpt4 key购买 nike

我有一个 Rails 应用程序,可以很好地加载开发中的所有 Assets 。

<link rel="stylesheet" href="/assets/reset.css" type="text/css" media="screen" title="no title" />
<link rel="stylesheet" href="/assets/text.css" type="text/css" media="screen" title="no title" />
<link rel="stylesheet" href="/assets/buttons.css" type="text/css" media="screen" title="no title" />
<link rel="stylesheet" href="/assets/theme-default.css" type="text/css" media="screen" title="no title" />
<link rel="stylesheet" href="/assets/login.css" type="text/css" media="screen" title="no title" />
<link rel="stylesheet" href="/assets/notify.css" type="text/css" media="screen" title="no title" />

而在生产服务器上,它仍然使用上面的代码来加载 CSS。它不应该改用/assets/applicaiton.css 文件吗?我已经在生产环境中手动运行了 rake assets:precompile 任务,我可以看到它已经在/public/assets 文件夹中创建了所需的文件。

那么,我需要做什么来告诉 Rails 使用压缩文件?

我的 production.rb 看起来像这样:-

  # Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true

# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true

最佳答案

你应该像这样使用 stylesheet_link_tag 助手来调用 css 文件:

= stylesheet_link_tag "application", :media => "all"

并将您的样式表插入到应用程序样式表文件中,例如:

= require reset
= require text
= require button
...

然后修改您的 production.rb 文件以将 config.assets.compile 设置为 true

 # Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true

# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true

# Generate digests for assets URLs
config.assets.digest = true

“应该工作”

关于ruby-on-rails - Rails 应用程序未在生产环境中使用预编译 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13515831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com