【发布时间】:2019-12-18 00:31:15
【问题描述】:
类似的帖子有this、this和this,但没有人回答问题。
all.js 如何在 Rails 3.2.12 的生产环境中编译?如下图的 production.rb 文件所示,编译资产被禁用,所以不清楚 all.js 最初是如何生成的。
运行rake assets:precompile 会产生以下错误:
rake 中止!不知道如何构建任务“资产:预编译”(见 可用任务列表 rake --tasks)
根本问题是如何更新 all.js 以反映 application.js 中的最新代码。重启服务器没有帮助,那么是什么触发 all.js 重新编译?
Test::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"
# For nginx:
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# If you have no front-end server that supports something like X-Sendfile,
# just comment this out and Rails will serve the files
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Disable Rails's static asset server
# In production, Apache or nginx will already do this
config.serve_static_assets = false
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# 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
# Defaults to Rails.root.join("public/assets")
# config.assets.manifest = YOUR_PATH
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
end
【问题讨论】:
-
你试过运行
rake assets:precompile任务吗?我不是 100% 虽然它可以在 rails 3 中使用 -
@arieljuod 是的,它给出了一个错误:
rake aborted! Don't know how to build task 'assets:precompile' (See the list of available tasks withrake --tasks)。有什么建议么?感谢您的帮助! -
根据 3.2 版指南,它应该使用该命令 guides.rubyonrails.org/v3.2/…
-
简单的解决方案是将此代码
Rails.application.config.assets.precompile += ['all.js']放入config/initializers/assets.rb
标签: ruby-on-rails ruby-on-rails-3 rubygems