2013-07-19 163 views
0

我創建了一個完整的引擎打包成一個gem,它允許我快速部署CSS,圖像,JS/JQuery項目以及一個對所有我的項目。在開發模式下,這一切都巧妙運作。 然而,試圖預編譯的資產在生產中使用拋出一個錯誤:ruby​​ rails 3.2 rake資產:針對引擎資產的預編譯失敗

# 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) 

我花了一點時間在這個問題拋出的網絡搜索,但沒有發現任何明顯相關。我希望我只是忘記了在設置'my_stock.engine'或my_example_app時做些事情,因爲這真的是我第一次嘗試做這樣的事情。

編輯:添加--trace結果

** 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:進一步挖掘和錯誤,CONFIGS的觀點:

my_example_app /應用/資產/ Java腳本/應用。 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 

...所以 「my_stock.engine」 是在資產路徑。

/EDIT2

預先感謝任何/所有幫助&建議!

+0

向我們展示跟蹤將幫助許多其他人就您的應用程序失敗的位置給出建議 – David

+0

完成。讓我知道你的想法。 – MichelV69

回答

0

這裏有幾個問題你需要問問自己。無論您是否正確設置了引擎。我還沒有涉足到建立一個Rails引擎,但是閱讀ruby on rails指南:adding assets to your gems。它強調:

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.

你可以看到自己這一點:jQuery-rails。我對上述引用的理解告訴我們,通過讓你的引擎類繼承Rails引擎,它應該繼承所有的Rails方法,並且正如它所說的那樣,通知目錄它可以包含資源。

而且這個你預編譯時需要考慮到的另一件事是它也指出:

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.

另一個警告此提出的是下面的,我覺得這是發生在你:

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.

您可以在上面的引用中看到:1)將此設置爲false可能會導致錯誤,因此您應該在本地進行測試。此外,它指出它會影響引擎。

主要部分

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.

所以說這一切我相信,如果你有config.assets.intialize_on_precompile設置爲false,那麼你的應用程序沒有被啓動。我希望這有助於解決問題,因爲我確實從中學到了一些東西。

更新回答

你如何,包括您的應用程序引擎重要的是要正確指定路徑依賴。由於來自跟蹤的錯誤消息表明它可能不在您的應用程序中。請檢查您無論是在路徑

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 

在你的Gemfile也depneds上有my_stock_engine.js你是如何增加它這很可能將是via path: '/some/path'

+0

大衛你好。感謝您的意見和建議,但是,似乎沒有任何問題。我剛剛更新了這個問題,並提供了一些新信息,這些信息是您的帖子指引我的。希望它會導致一個解決方案。 – MichelV69

+0

@ MichelV69'my_stock.engine.js'是以下任一項:'my_stock.engine.js','my_stock.engine.js','my_stock.engine.js'?因爲肯定你的錯誤一定是來自這裏。也是'/ my_stock.engine'中的寶石代碼。這一切都取決於你如何在gemfile中添加gem。你最有可能通過路徑:'/ some/path'' – David

+0

大衛:我想到了這個星期五晚些時候,並檢查。果然,出於某種原因,'my_stock.engine.js'只是'my_stock.js'。在開發模式下,它運行得很好,但在生產模式下顯式路徑會窒息。 請將您的評論輸入正確的答案,以便我可以接受。我感謝您的幫助。 – MichelV69

0

我已經走得通相同的動作試圖創建一個封裝了一些自定義JavaScript插件的gem。您的問題看起來是您的引擎寶石未正確包含在示例應用程序gemfile中,或者引擎寶石未正確安裝在您的寶石回購中。你做了gem install mystock.engine-0.0.1.gem或類似的,然後在你的示例應用程序bundle install --local?這將確保您的自定義引擎在本地安裝,然後拉入您的示例應用程序。如果是這種情況,我期望看到您的引擎資源列在'/.rvm/gems/'路徑下,就像您的gemfile中的其他寶石一樣。祝你好運!