Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

config.assets.precompile ignored with recommended settings #10428

Closed
iamveen opened this Issue · 15 comments

8 participants

@iamveen

config.assets.precompile is ignored if using the suggested format from rails guides.

config.assets.precompile += ['test.js']   # ignored
config.assets.precompile << 'test.js'  # works

Both pieces of code produce the same array, but in the former, additions are not compiled.

I made a new app to verify something wasn't amiss in my larger app, and the same problem occurs.

Rails 4.0.0.beta1
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0]

# default production.rb

pipe-test ❯ RAILS_ENV=production rake assets:precompile
[#<Proc:0x007ff48c920350@/Users/gdunne/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sprockets-rails-2.0.0.rc4/lib/sprockets/railtie.rb:39 (lambda)>, /(?:\/|\\|\A)application\.(css|js)$/]
INFO -- : Writing .../public/assets/rails-d8fb6a2617998f32edf5edb354fc5326.png
INFO -- : Writing .../public/assets/application-d4a508061cd56ce9e544945495285e0c.js
INFO -- : Writing .../public/assets/application-fa5fb97555c828140aa155ca341aaff3.css



# production.rb as per: http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
# config.assets.precompile += ['test.css', 'test.js']

pipe-test ❯ RAILS_ENV=production rake assets:precompile                                                                             ⏎
[#<Proc:0x007f884a8a4358@/Users/gdunne/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sprockets-rails-2.0.0.rc4/lib/sprockets/railtie.rb:39 (lambda)>, /(?:\/|\\|\A)application\.(css|js)$/, "test.css", "test.js"]
INFO -- : Writing .../public/assets/rails-d8fb6a2617998f32edf5edb354fc5326.png
INFO -- : Writing .../public/assets/application-d4a508061cd56ce9e544945495285e0c.js
INFO -- : Writing .../public/assets/application-fa5fb97555c828140aa155ca341aaff3.css



# production.rb:
# ['test.css', 'test.js'].each do |asset|
#  config.assets.precompile << asset
# end

pipe-test ❯ RAILS_ENV=production rake assets:precompile
[#<Proc:0x007fd7c4338328@/Users/gdunne/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sprockets-rails-2.0.0.rc4/lib/sprockets/railtie.rb:39 (lambda)>, /(?:\/|\\|\A)application\.(css|js)$/, "test.css", "test.js"]
INFO -- : Writing .../public/assets/rails-d8fb6a2617998f32edf5edb354fc5326.png
INFO -- : Writing .../public/assets/application-d4a508061cd56ce9e544945495285e0c.js
INFO -- : Writing .../public/assets/test-a3b89b66a8471f3e75abb239e3b35c7d.js
INFO -- : Writing .../public/assets/application-fa5fb97555c828140aa155ca341aaff3.css
INFO -- : Writing .../public/assets/test-a3b89b66a8471f3e75abb239e3b35c7d.css
@pbrisbin

Indeed, the following test case fails:

    test "precompile allows for += syntax" do
      add_to_config "config.assets.precompile += [ 'something.js' ]"

      precompile!

      assert_file_exists("#{app_path}/public/assets/something-*.js")
    end
@pftg

@pbrisbin you forget to add: app_file "app/assets/javascripts/something.js.erb", "alert();"

Have not reproduce it for master and for Ruby 1.9.3 and 2.0.0 by adding tests. Will investigate more.

@pftg pftg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@pftg

Ok, found the problem: this happen only when config.assets.precompile += ['test.css', 'test.js'] added in environments file like production.rb. I think, Sprockets already use reference for the array before environment invoked.

@iamveen

That makes sense. It never occurred to me that += returns a new array, while << appends to the existing one.

@pftg pftg referenced this issue in rails/sprockets-rails
Closed

Read assets options changed in environment #50

@pftg pftg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@courtsimas

2 wasted days, and an << fixes my issue. Dumb bug.

@guilleiguaran guilleiguaran was assigned
@dhh
Owner
dhh commented

If you had this problem, please help test the fix: rails/sprockets-rails#63

@pftg

@dhh I added tests for this bug in #10537 and rails/sprockets-rails#50 but they have not been reviewed :(

@guilleiguaran

@pftg can you check if rails/sprockets-rails#63 is working fine with your apps?

@pftg pftg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@pftg pftg referenced this issue from a commit in jetthoughts/rails
@pftg pftg #10428: Added tests for config.assets.precompile
Tests for bug in sprocket-rails:
  do not use value of configuration options
  which changed after environment loaded
9da48a9
@enwood

I just generated a new, blank app with Rails 4.0.0 and see that production.rb is still generated with the following comment:

 # Precompile additional assets.
  # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
  # config.assets.precompile += %w( search.js )

Not being intimately acquainted with Sprockets and precompilation, and having tried to chase this thread of why specified assets in environment config files aren't being precompiled, is the "+=" syntax approach still/now acceptable? What about @iamveen's comment above that "that += returns a new array, while << appends to the existing one".

Is white-listing assets in the environment configuration files now working correctly for Rails 4.0.0? And, by what means should it be made to work correctly for Rails 3.2.x?

@pftg

May you share your application on github with this problem?

@enwood

Hi Paul;

I'm afraid I can't. It's not that I have an immediate problem; I've just been trying to sort out what the correct approach is now and what has been fixed. In my Rails 3.2.12 app, this approach:

config.assets.precompile += w%[  application-print.css ]

didn't work (application-print.css was not precompiled, nor copied to public/assets), but this approach:

config.assets.precompile << 'application-print.css' 

does work.

So, I am surprised to see a new Rails 4.0.0 app still generating the "+=" syntax. Has Rails 4.0.0 (or Sprockets) been fixed to correctly handle this now? I'm just trying to unravel this very complex thread and related issues.

Thanks,
Tim

@rafaelfranca

Have you tried using 4-0-stable?

@enwood

Hi Rafael;

No, it's not that I have a problem with this. I'm just trying to ascertain what the CORRECT approach is now with both Rails 3.2.x and Rails 4.0. Please see the questions in my previous posting.

Tim

@rafaelfranca

The correct approach is what it always was, using +=.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.