digest_path和asset_digest_path不允许摘要URL

我在生产资产方面遇到了非常艰难的时期。 它归结为我试图覆盖sprokets助手模块,试图看看是什么…当我重新写入以下内容时:

module Sprockets module Rails module Helper def compute_asset_path(path, options = {}) 

它不会运行。 我在我的本地环境中尝试过,它运行得很好。 生产环境是否有理由不允许我的资产以摘要forms呈现,但我的本地环境会如何? 这与绅士的要求有关……

Rails 4.0.3使用asset_sync生成不正确的资产路径

这是我在尝试覆盖该方法后收到的错误(在使用RAILS_ENV = development时运行时没有错误):

 ActionView::Template::Error (undefined local variable or method `digest_path' for #<#:0x000001034a81d0>): 

Gemfile中的Asset Gems供参考:

 source 'http://rubygems.org' # ruby '2.1.1' gem 'rails', '4.0.4' gem 'jbuilder', '~> 1.2' gem 'devise' gem 'devise_invitable' gem 'figaro' gem 'mysql2' gem 'simple_form' gem 'kaminari' gem 'statistics' gem 'possessive' gem 'geocoder' gem 'nokogiri' gem 'asset_sync' gem 'sprockets-rails', :require => 'sprockets/railtie' gem 'ledermann-rails-settings', :require => 'rails-settings' gem 'public_activity' group :assets do gem 'therubyracer' gem 'sass-rails', '~> 4.0.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' end group :development do gem 'better_errors' gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx] gem 'guard-bundler' gem 'guard-rails' gem 'quiet_assets' gem 'rails_layout' gem 'rb-fchange', :require=>false gem 'rb-fsevent', :require=>false gem 'rb-inotify', :require=>false end group :test do gem 'email_spec', '>= 1.4.0' gem 'launchy', '>= 2.2.0' gem 'capybara', '>= 2.0.3' gem 'database_cleaner', '>= 1.0.0.RC1' gem 'cucumber-rails', '>= 1.3.1', :require => false end group :production do gem 'rails_12factor' end gem 'rspec-rails', '>= 2.12.2', :group => [:development, :test] gem 'factory_girl_rails', '>= 4.2.0', :group => [:development, :test] gem 'teaspoon', '>= 0.7.4', :group => [:development, :test] gem 'cancan', '>= 1.6.9' gem 'rolify', '>= 3.2.0' gem 'stripe-rails' gem 'faker' gem 'open4' gem 'unf' 

当我在开发模式下运行它时,它运行完全正常。 当我通过生产模式(即使使用相同的配置文件)运行它时,它不会inheritance像digest_pathasset_digest_path的View属性为null或manifest等。

 module Sprockets module Rails module Helper def compute_asset_path(path, options = {}) if digest_path = asset_digest_path(path) path = digest_path if true # BUG: digest assets doesn't work on live, let's just bake it path += "?body=1" if options[:debug] File.join(assets_prefix || "/", path) else super end end def asset_digest_path(path, options = {}) if manifest = assets_manifest if digest_path = manifest.assets[path] return digest_path end end if environment = assets_environment if asset = environment[path] return asset.digest_path end end end end end end module ActionView module Helpers module AssetUrlHelper def compute_asset_path(source, options = {}) dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || "" File.join(dir, source) end end end end 

希望这将有助于拯救我的同事程序员朋友一些头撞:D

我正在将文件上传到S3,我没有意识到Rails没有加载清单。 您可以正确设置所有生产设置(如上面和其他线程),但如果您没有Rails可读的manifest.json文件,它仍会生成/ javascript / *(示例)URL。

我在使用multi_json gem的最新版本时仍然遇到问题,因此我将其降级为1.7.8并且工作正常。

 gem 'multi_json', '1.7.8' 

这样就可以读取rake assets:precompile创建的manifest.json文件。

关于这个链接线程https://github.com/rails/sprockets-rails/issues/107关于你的清单文件应该是git还是只是在部署脚本上有争议,做最适合你的事情,只需确保它可以在:

 /public/assets/manifest.json 

或者自己指定

 config.assets.manifest = '...' 

这可能会也可能不会被贬低。

干杯!