Ruby on rails 资产管道在生产中不工作,尝试了所有签名
我在heroku上有一个rails 3.2应用程序。我已经尝试了我能找到的一切,试图修复javascripts没有在生产模式下加载的事实。不过在dev中一切都很好。此外,部署到heroku时,预编译失败。但是,当我查看prod中的源代码时,我可以清楚地看到javascripts文件(/assets/application-32fdbd115c5d59c7be2876c10363600.js)正在加载并包含内容 我已经尝试了我能想到和读到的每一种设置。我不太清楚该怎么办。以下是我当前在production.rb中的设置:Ruby on rails 资产管道在生产中不工作,尝试了所有签名,ruby-on-rails,asset-pipeline,Ruby On Rails,Asset Pipeline,我在heroku上有一个rails 3.2应用程序。我已经尝试了我能找到的一切,试图修复javascripts没有在生产模式下加载的事实。不过在dev中一切都很好。此外,部署到heroku时,预编译失败。但是,当我查看prod中的源代码时,我可以清楚地看到javascripts文件(/assets/application-32fdbd115c5d59c7be2876c10363600.js)正在加载并包含内容 我已经尝试了我能想到和读到的每一种设置。我不太清楚该怎么办。以下是我当前在produc
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = false
config.assets.compile = true
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
在environment.rb中:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
App::Application.initialize!
application.rb:
require File.expand_path('../boot', __FILE__)
require "rails/all"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module App
class Application < Rails::Application
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
我所做的一切似乎都无法让它在本地机器或heroku上的生产模式下工作。但是,它在开发中运行得很好。在您的生产环境中您是否尝试过:
RAILS\u ENV rake资产:预编译在您的生产环境中您是否尝试过:RAILS\u ENV rake资产:预编译我终于想出了如何修复这个问题,尽管我不知道修复有多好。基本上,问题在于将.js文件压缩到application.js会导致问题。在production.rb中,我提出了以下内容:
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = false
# 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
config.assets.debug = true
这解决了问题。但是,现在它不再列出application.js,而是列出所有资产文件。我不确定这是否有任何长期问题。我终于找到了解决办法,尽管我不知道这有多好。基本上,问题在于将.js文件压缩到application.js会导致问题。在production.rb中,我提出了以下内容:
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = false
# 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
config.assets.debug = true
这解决了问题。但是,现在它不再列出application.js,而是列出所有资产文件。我不确定这是否有任何长期问题。您是否尝试重新启动Heroku<代码>heroku重新启动
您尝试过重新启动heroku吗heroku restart
是的,我尝试了几次不同的方法…但是没有luckDo您收到任何类型的错误消息,或者只是服务资产失败?我没有看到任何错误消息,但是在尝试加载资产时,我在本地计算机上收到402响应。这很奇怪,因为我在源代码中看到Java脚本被压缩到application.js文件中。在heroku上,我确实收到了一个错误,预编译失败了。同样,我在.js文件中看到了资产。很奇怪,我刚想出来。。。在生产中,如果我执行?debug_assets=1,它将修复该问题。这意味着问题的原因是,所有内容都放在单个application.js文件中。你知道如何在不关闭压缩的情况下解决这个问题吗?是的,我尝试了几种不同的方法和次数…但是没有任何luckDo您收到任何类型的错误消息,或者只是无法为资产提供服务?我没有看到任何错误消息,但是在尝试加载资产时,我在本地计算机上收到402响应。这很奇怪,因为我在源代码中看到Java脚本被压缩到application.js文件中。在heroku上,我确实收到了一个错误,预编译失败了。同样,我在.js文件中看到了资产。很奇怪,我刚想出来。。。在生产中,如果我执行?debug_assets=1,它将修复该问题。这意味着问题的原因是,所有内容都放在单个application.js文件中。你知道如何在不关闭压缩的情况下解决这个问题吗?