【问题标题】:rails production 'css isn't precompiled'rails production 'css 未预编译'
【发布时间】:2012-01-09 21:30:30
【问题描述】:

我已经在我的 Leopard 网络服务器上使用生产的 Rails 3.1 姐妹应用程序完成了这项工作。所以我没想到部署这个应用程序会如此迷失。我已经让乘客识别该应用程序,但我在 apache 中收到“[GET /] miss”错误。环顾四周,我想我可以让它在 webrick 中运行,看看我是否可以隔离问题。

捆绑 exec rake 资产:预编译 RAILS_ENV=production

但是当我加载 localhost:3000 我得到“blueprint/screen.css is not precompiled”

我开始比较姐妹应用之间的差异,但找不到它们。以下是他们分享的一些关键代码:

<%= stylesheet_link_tag "application" %>
  <%= javascript_include_tag "application" %> #in app/views/layouts/application.html.erb

config/environments/production.rb
config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.precompile += %w( search.js )
  config.assets.precompile += %w( blueprint/screen.css blueprint/print.css )
  config.assets.precompile += %w( *.css *.js )

这发生在 3.1.0 和 3.1.3 中,我可以确认预编译发生在蓝图目录中。我在忽略什么?,山姆

【问题讨论】:

  • 我遇到了一个“陷阱”,我在%w() 中用逗号分隔我的项目,这些逗号成为数组项目的一部分,而不是分隔它们。例如。 %w( blueprint/screen.css, blueprint/print.css ) #=&gt; ['blueprint/screen.css,', 'blueprint/print.css']

标签: ruby-on-rails-3


【解决方案1】:

你试过这样分开吗?

config.assets.precompile += %w( blueprint/screen.css )
config.assets.precompile += %w( blueprint/print.css )

然后运行:

bundle exec rake assets:precompile RAILS_ENV=production

这应该修复它。

【讨论】:

  • 应该有。我的是这样的:config.assets.precompile += %w(blueprint/screen.css blueprint/print.css)
  • 只是好奇,为什么在单独的行中附加预编译数组可以解决他的问题?
【解决方案2】:

您可以在生产环境中将 assets.compile 设置为 true 以在文件丢失时回退到资产管道。

# config/environments/production.rb
# ...
# Fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = true

【讨论】:

  • 这当然解决了症状,但它隐藏了问题可以修复并且应该 被修复。
猜你喜欢
  • 1970-01-01
  • 2014-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多