0

I've created a full engine packaged as a gem that allows me to quickly deploy CSS, images, JS/JQuery items and a working User model that is common to all of my projects. In development mode, it all works smartly. However, trying to precompile the assets for use in production throws an error:

# RAILS_ENV=production bundle exec rake assets:precompile
/usr/local/bin/ruby /usr/local/bin/rake assets:precompile:all RAILS_ENV=production

RAILS_GROUPS=assets
rake aborted!
couldn't find file 'my_stock.engine'
  (in my_example_app/app/assets/javascripts/application.js:17)

Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby /usr/local/bin/rake as...]

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

I've spent a bit of time throwing web searches at this problem, but have not found anything obviously related. I expect I've simply forgotten to do something in setting up 'my_stock.engine' or in my_example_app, since this is really the first time I've tried to do something like this.

EDIT: Adding --trace results

** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/bin/ruby /usr/local/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
couldn't find file 'my_stock.engine'
  (in /opt/bv_applets/meetme_manager/app/assets/javascripts/application.js:17)
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:102:in `resolve'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:142:in `require_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:215:in `process_require_directive'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:165:in `block in process_directives'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:163:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:163:in `process_directives'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:97:in `evaluate'
/usr/local/lib/ruby/gems/1.9.1/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processed_asset.rb:12:in `initialize'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `new'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `block in build_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:270:in `circular_call_protection'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:248:in `build_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:60:in `find_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/bundled_asset.rb:16:in `initialize'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `new'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `build_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:60:in `find_asset'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/static_compiler.rb:19:in `block in compile'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:219:in `block in each_logical_path'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each_entry'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:204:in `block in each_file'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each_file'
/usr/local/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:217:in `each_logical_path'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/static_compiler.rb:18:in `compile'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:56:in `internal_precompile'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:70:in `block (3 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile:primary
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby /usr/local/bin/rake as...]
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/file_utils.rb:55:in `block in create_shell_runner'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/file_utils.rb:45:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/file_utils.rb:45:in `sh'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/file_utils_ext.rb:37:in `sh'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/file_utils.rb:82:in `ruby'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/file_utils_ext.rb:37:in `ruby'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile

/EDIT

EDIT2: Further digging and review of the error and configs:

my_example_app/app/assets/javascripts/application.js

13: //= require jquery
14: //= require jquery_ujs
15: //= require jquery.ui.datepicker
16: //= require_tree .
17: //= require my_stock.engine

The Rails Asset Pipeline Config Path:

$ be rails c

 ------
Loading development environment (Rails 3.2.13)
1.9.3-p392 :001 > y Rails.application.config.assets.paths
---
- /my_example_app/app/assets/images
- /my_example_app/app/assets/javascripts
- /my_example_app/app/assets/stylesheets
- /my_example_app/vendor/assets/javascripts
- /my_example_app/vendor/assets/stylesheets
- /.rvm/gems/ruby-1.9.3-p392/gems/jquery-rails-3.0.4/vendor/assets/javascripts
- /.rvm/gems/ruby-1.9.3-p392/gems/jquery-ui-rails-4.0.3/app/assets/images
- /.rvm/gems/ruby-1.9.3-p392/gems/jquery-ui-rails-4.0.3/app/assets/javascripts
- /.rvm/gems/ruby-1.9.3-p392/gems/jquery-ui-rails-4.0.3/app/assets/stylesheets
- /.rvm/gems/ruby-1.9.3-p392/gems/twitter-bootstrap-rails-2.2.7/app/assets/fonts
- /.rvm/gems/ruby-1.9.3-p392/gems/twitter-bootstrap-rails-2.2.7/app/assets/images
- /.rvm/gems/ruby-1.9.3-p392/gems/twitter-bootstrap-rails-2.2.7/app/assets/javascripts
- /.rvm/gems/ruby-1.9.3-p392/gems/twitter-bootstrap-rails-2.2.7/app/assets/stylesheets
- /.rvm/gems/ruby-1.9.3-p392/gems/coffee-rails-3.2.2/lib/assets/javascripts
- /.rvm/gems/ruby-1.9.3-p392/gems/bootstrap-sass-2.3.2.1/vendor/assets/images
- /.rvm/gems/ruby-1.9.3-p392/gems/bootstrap-sass-2.3.2.1/vendor/assets/javascripts
- /.rvm/gems/ruby-1.9.3-p392/gems/bootstrap-sass-2.3.2.1/vendor/assets/stylesheets
- /my_stock.engine/app/assets/images
- /my_stock.engine/app/assets/javascripts
- /my_stock.engine/app/assets/stylesheets
 => nil
1.9.3-p392 :002 > exit

... so "my_stock.engine" is in the assets path.

/EDIT2

Thanks in advance for any / all help & suggestions!

MichelV69
  • 1,247
  • 6
  • 18

2 Answers2

0

Theres a few questions you need to ask yourself. Whether you have set up your engine correctly. I have not dabbled with setting up a Rails engine myself but having read ruby on rails guide: adding assets to your gems. It highlights:

This gem contains an engine class which inherits from Rails::Engine. By doing this, Rails is informed that the directory for this gem may contain assets and the app/assets, lib/assets and vendor/assets directories of this engine are added to the search path of Sprockets.

You can see this for yourself: jQuery-rails. My understanding of the quote above tells that by making your by making your engine class inherit the Rails engine this should inherit all the Rails methods along with it and as it says inform the directory that it can contain the assets.

Further to this another thing you need to take into account when precompiling is it also stated that:

For faster asset precompiles, you can partially load your application by setting config.assets.initialize_on_precompile to false in config/application.rb, though in that case templates cannot see application objects or methods. Heroku requires this to be false.

Another warning this puts forward is the following which I think this is happening to you:

If you set config.assets.initialize_on_precompile to false, be sure to test rake assets:precompile locally before deploying. It may expose bugs where your assets reference application objects or methods, since those are still in scope in development mode regardless of the value of this flag. Changing this flag also affects engines. Engines can define assets for precompilation as well. Since the complete environment is not loaded, engines (or other gems) will not be loaded, which can cause missing assets.

You can see here in the above quote that 1) having this set to false may cause bugs so you should test locally. Further to this it points out that it affects the engines.

Main Part

Engines can define assets for precompilation as well. Since the complete environment is not loaded, engines (or other gems) will not be loaded, which can cause missing assets.

So in saying all of this I believe that if you have the config.assets.intialize_on_precompile set to false then your app is not being started. I hope this helps out as I sure learned something from this as well.

Updated Answer

Dependent on how you are including the engine in your application it is important to specify the path correctly. As the error message from your trace indicates that it may not be located in your application. Please check if you have my_stock_engine.js in either of the paths

app/assets/javascript/my_stock_engine.js
app/vendor/assets/javascript/my_stock_engine.js
app/lib/assets/my_stock_engine.js
my_stock_engine/app/assets/javascript/my_stock_engine.js

In your Gemfile it also depneds on how you have added it which most probably will be via path: '/some/path'

Deej
  • 5,334
  • 12
  • 44
  • 68
  • Hello, David. Thanks for your comments and suggestions, however, none of that seems to be the issue. I've just updated the question with some new information that your post directed me to. Hopefully it leads to a solution. – MichelV69 Jul 25 '13 at 19:46
  • @MichelV69 Is `my_stock.engine.js` is any of the following: ` my_stock.engine.js`, ` my_stock.engine.js`, ` my_stock.engine.js`? Because surely your error must be coming from here. Also is the gem code in the `/my_stock.engine`. As this all depends on how you added the gem in your gemfile. Which you most probably did `via path: '/some/path'` – Deej Jul 27 '13 at 21:16
  • David: I thought of that late Friday and checked. Sure enough, for some reason, 'my_stock.engine.js' was just 'my_stock.js'. In development mode, it ran just fine but with explicit paths in production mode it would choke. Put your comment into a proper answer so I can accept it, please. I appreciate your help. – MichelV69 Jul 29 '13 at 12:35
  • @MichelV69 see my answer which is corresponding to my comment. – Deej Jul 29 '13 at 12:58
0

I have been going thru the same motions trying to create a gem that wraps up some custom javascript plugins. Your problem looks to be that your engine gem isn't properly included in your example app gemfile and/or the engine gem isn't properly installed in your gem repo. Did you do a gem install mystock.engine-0.0.1.gem or similar, and then on your example app a bundle install --local? That will ensure that your custom engine is installed locally and then pulled into your example app. If that were the case I would expect to see your engine's assets listed underneath a '/.rvm/gems/' path just like the other gems in your gemfile. Good luck!