Rails 具有资产的宝石不会添加到 config.assets.paths

Rails gems that have assets are not added to config.assets.paths

我正在将 Rails 3.0 应用程序升级到 Rails 4.2。在 Rails 3.1 中添加资产管道后,我注意到包含资产的 gem 未添加到 Rails.application.config.assets.paths

我将这些宝石添加到我的 Gemfile

gem 'jquery-rails'
gem 'jquery-ui-rails'

我希望将这些目录添加到 Rails.application.config.assets.paths

 ~/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/jquery-ui-rails-5.0.5/app/assets/images
 ~/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/jquery-ui-rails-5.0.5/app/assets/javascripts
 ~/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/jquery-ui-rails-5.0.5/app/assets/stylesheets
 ~/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/jquery-rails-4.0.3/vendor/assets/javascripts

但是,它只显示我的 app/assets 文件夹中的文件夹。这是 Rails.application.config.assets 的完整输出。我在其他 Rails 应用程序中有完全相同的配置,但我没有遇到此问题。

 {:_blocks=>
   [#<Proc:0x007fa6070a9b50@~/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:126>,
    #<Proc:0x007fa6070a9948@~/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:130>,
    #<Proc:0x007fa6070a9600@~/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:137>,
    #<Proc:0x007fa6070a8fc0@~/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:149>,
    #<Proc:0x007fa6070a8958@~/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:153>,
    #<Proc:0x007fa6070a87f0@~/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:157>],
  :paths=>
   ["~/my-app/app/assets/images",
    "~/my-app/app/assets/javascripts",
    "~/my-app/app/assets/stylesheets"],
  :precompile=>
   [#<Proc:0x007fa6070ab680@~/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:84 (lambda)>,
    /(?:\/|\|\A)application\.(css|js)$/],
  :prefix=>"/assets",
  :manifest=>nil,
  :quiet=>false,
  :version=>"1.0",
  :debug=>true,
  :compile=>true,
  :digest=>true,
  :cache_limit=>52428800,
  :gzip=>true,
  :check_precompiled_asset=>true,
  :compress=>false,
  :raise_runtime_errors=>true,
  :enabled=>true,
  :logger=>false,
  :resolve_with=>[:environment]}

很可能您在 Gemfile 中还有 assets 组。

assets 分组概念是 Rails 3 的遗物,has been removed in rails 4.0

Rails 4.0 removed the assets group from Gemfile. You'd need to remove that line from your Gemfile when upgrading.

在我最近从 3.0 升级到 4.0 的 rails 应用程序中,包括 assets 组中的 gem 阻止了 gem 资产被包含在 Rails.application.config.assets.paths。从 Gemfile 中删除 assets 组,并更新包解决了问题。