gpt4 book ai didi

ruby-on-rails - Assets 预编译未在 heroku cedar for rails 3.2 应用程序上运行

转载 作者:数据小太阳 更新时间:2023-10-29 06:40:58 25 4
gpt4 key购买 nike

本周开始开发一个新应用程序,该应用程序运行带有 Assets 管道的最新 Rails 3.2.2。对于 Assets ,我希望在将应用程序推送到 heroku 时编译 Assets (而不是必须手动编译并将编译后的 Assets 存储在 repo 中)。 The docs suggest this should happen automatically .

我遇到的问题是,当我运行 git push heroku master 时,它似乎根本没有运行 rake assets:precompile 任务。 Assets 永远不会被编译。这是我得到的输出:

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.rc.7
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
Using rake (0.9.2.2)
.......
.......
Your bundle is complete! It was installed into ./vendor/bundle
Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Rails plugin injection
Injecting rails_log_stdout
Injecting rails3_serve_static_assets
-----> Discovering process types
Procfile declares types -> web
Default types for Ruby/Rails -> console, rake, worker
-----> Compiled slug size is 61.7MB
-----> Launching... done, v30
[appname] deployed to Heroku

我在我的 application.rb 中启用了 Assets 管道

require File.expand_path('../boot', __FILE__)

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"

Bundler.require *Rails.groups(:assets) if defined?(Bundler)

module Appname
class Application < Rails::Application
# ...

# Enable the asset pipeline
config.assets.enabled = true

# Do not boot the app when precompiling assets
config.assets.initialize_on_precompile = false
end
end

任何人都知道可能导致问题的原因是什么?如果需要,我很乐意提供更多代码。如果我运行 heroku info,它会显示我正在 Cedar 堆栈上运行。

我不得不打开 config.assets.compile = true 以停止在生产中收到 500 个错误,尽管这会在运行时编译 Assets (我不希望这样)。

最佳答案

这似乎已经解决了。我相信这是由于 Rakefile 没有加载 assets:production 中的预编译任务造成的。

rakefile 正在加载未捆绑到生产中的 cucumber 和 rspec gem 的任务。因此,assets:precompile 任务在生产环境中不可用,因此 heroku 没有尝试运行它。

我将测试任务包装在环境检查条件中,如下所示:

if %(development test).include?(Rails.env)
require 'rspec/core'
require 'rspec/core/rake_task'
end

关于ruby-on-rails - Assets 预编译未在 heroku cedar for rails 3.2 应用程序上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9683669/

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