简体   繁体   中英

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

I am upgrading a Rails 3.0 application to Rails 4.2. Upon adding the asset pipeline in Rails 3.1, I noticed that gems that contain assets are not added to Rails.application.config.assets.paths

I added these gems to my Gemfile

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

I would expect that to add these directories to 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

However, it only shows the folders in my app/assets folder. Here is the complete output of Rails.application.config.assets . I have the exact same configuration in other Rails applications where I am not experiencing this problem.

 {:_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]}

Quite likely you still have the assets group in the Gemfile .

The assets grouping concept is a relic from Rails 3, and 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.

On a rails app that I upgraded recently from 3.0 to 4.0, including the gems in assets group prevented the gem assets from being included in Rails.application.config.assets.paths . Removing the assets group from the Gemfile, and updating the bundle fixed the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM