-->

Rails 3.2.11 asset precompile fails if threadsafe!

2019-08-02 09:25发布

问题:

I'm on Rails 3.2.11 and ruby 1.9.3.125

My app is working ok in devel and production if threadsafe! off

With threadsafe! enabled I get an error during precompiling, in my asset assetsolutions.js.erb (which is the main js file of the application) I use the Workorder class as in the next line if ($('#workorder_worktype').val()=='<%= Workorder::REPAIR %>')

with threadsafe! the class can't be found at precompile time, I've done some reasearch and I think it may be related with rails switching off eager loading if threadsafe! is on

How can I include the Workorder class to make precompile work?

error follows:

c:/rails3/ruby/bin/ruby.exe c:/rails3/Ruby/bin/rake assets:precompile:all RAILS_ ENV=production RAILS_GROUPS=assets rake aborted! uninitialized constant #::Workorder (in C:/rails3/applications/assetsolutions/app/assets/javascripts/preloaded/ass etsolution.js.erb) C:/rails3/applications/assetsolutions/app/assets/javascripts/preloaded/assetsolu tion.js.erb:763:in `evaluate_source' Tasks: TOP => assets:precompile:primary (See full trace by running task with --trace) rake aborted! Command failed with status (1): [c:/rails3/ruby/bin/ruby.exe c:/rails3/Ruby...]

Tasks: TOP => assets:precompile (See full trace by running task with --trace)

Tnx Fabio

回答1:

I just had the same issue on a Rails 3.2.13 application and I solved it by adding config.eager_load = true to my config/environments/production.rb file. This also solved eager loading issues I had with rake not loading models.