さて、私はここでアプリケーションのフロントエンドとバックエンドのMVCをいじっている大きな男の子と女の子と遊んでいることを知っています(bboneは正確にはMVCではありませんが)が、これは私がこれまでに取り組んだ最初の本当に堅牢なアプリケーションです、そして残念ながら、アカデミックな領域にいるので、サポートはありません。特に最先端のサポートがないので、事前に感謝しています。
Rails(3.2.2)アプリを使用してHerokuにデプロイしようとするとエラーが発生し、アセットパイプラインが常に問題を引き起こしています。フロントエンドにBBoneを使用しており、[single] page [app]はロード時の画像とサウンドへのパスを知る必要があるため、この要点を使用して、パスするApp.assetsに画像パスをアタッチする必要がありました。application.js
フロントエンドでビルドされているアプリケーションを開始するためのrequire.jsのファイル。
問題は、Deviseが望んでいることであるように見えます:config.assets.initialize_on_precompile = false
require wants:config.assets.initialize_on_precompile = true
であり、Herokuはproduction.rbファイルで次のように望んでいます:config.assets.compile = true
。
私が得ているエラーは、モデル内の最後から2番目の行assets.js.erb
のすべての曲を取得するためにDBが呼び出されるgistファイルにありますSong
App = {};
App.assets = {
// Returns an object containing all of asset pipeline's image paths.
//
// Sample:
//
// {
// avatars/missing_avatar.png: "/assets/avatars/missing_avatar.png"
// chosen-sprite.png: "/assets/chosen-sprite.png"
// circle_green.png: "/assets/circle_green.png"
// circle_orange.png: "/assets/circle_orange.png"
// circle_red.png: "/assets/circle_red.png"
// circle_yellow.png: "/assets/circle_yellow.png"
// document.png: "/assets/document.png"
// }
//
// This hash is because Rails' Asset Pipeline bundles the routes to files
// per user session, then hands that to the user's session browser, for security.
// So we create in Ruby (erb = embedded ruby) a hash of the images to be accessed
// in the JS.
images: {
<% AssetsUtil.images.each do |img| %>
"<%= img %>" : "<%= asset_path(img) %>",
<% end %>
},
// Return a formatted URL for an asset.
//
// Sample:
//
// "/assets/document/png."
//
path: function(name) {
// If the file is in our images object, pull the path from there.
if (this.images && this.images[name]) {
return this.images[name];
}
// Otherwise, create a generic asset path.
return '/assets/' + name;
}
};
// Currently this is ALL the songs in the DB, not just the current_user 's songs
App.songs = {
songs: <%= Song.all.to_json.html_safe %>
};
rake assets:precompile
Herokuにデプロイする前に、提案されたとおりに実行しようとすると、完全なトレースエラーが発生します。
** Invoke assets:precompile (first_time)
** Invoke requirejs:precompile:external (first_time)
** Invoke requirejs:test_node (first_time)
** Execute requirejs:test_node
** Execute requirejs:precompile:external
/Users/me/.rvm/rubies/ruby-1.9.3-p362/bin/ruby /Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake requirejs:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke requirejs:precompile:all (first_time)
** Invoke requirejs:precompile:prepare_source (first_time)
** Invoke requirejs:setup (first_time)
** Invoke assets:environment (first_time)
** Invoke requirejs:precompile:disable_js_compressor (first_time)
** Execute requirejs:precompile:disable_js_compressor
** Execute assets:environment
** Execute requirejs:setup
** Invoke requirejs:clean (first_time)
** Invoke requirejs:setup
** Execute requirejs:clean
** Execute requirejs:precompile:prepare_source
rake aborted!
uninitialized constant Song
(in /Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb)
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:48:in `block in singletonclass'
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:65530:in `instance_eval'
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:65530:in `singletonclass'
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:65528:in `__tilt_70168709646800'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/tilt-1.3.4/lib/tilt/template.rb:144:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/tilt-1.3.4/lib/tilt/template.rb:144:in `evaluate'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/tilt-1.3.4/lib/tilt/template.rb:77:in `render'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/context.rb:177:in `block in evaluate'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `evaluate'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `new'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `block in build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:262:in `circular_call_protection'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:240:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/bundled_asset.rb:16:in `initialize'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `new'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/requirejs-rails-0.9.1/lib/tasks/requirejs-rails_tasks.rake:94:in `block (4 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:212:in `block in each_logical_path'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:200:in `block (2 levels) in each_file'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each_entry'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:198:in `block in each_file'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each_file'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:210:in `each_logical_path'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/requirejs-rails-0.9.1/lib/tasks/requirejs-rails_tasks.rake:92:in `block (3 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `load'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `<main>'
Tasks: TOP => requirejs:precompile:all => requirejs:precompile:prepare_source
rake aborted!
Command failed with status (1): [/Users/me/.rvm/rubies/ruby-1.9.3-p362...]
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `sh'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `sh'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/file_utils.rb:80:in `ruby'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `ruby'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.2/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/requirejs-rails-0.9.1/lib/tasks/requirejs-rails_tasks.rake:85:in `block (3 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/me/.rvm/gems/ruby-1.9.3-p362@global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `load'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `<main>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `eval'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => assets:precompile => requirejs:precompile:external
gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'railroady'
gem 'sqlite3'
# For linux support
gem 'therubyracer'
end
group :production do
gem 'pg'
gem 'thin'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'uglifier', '>= 1.0.3'
end
# gem "better_errors", ">= 0.2.0", :group => :development
# gem "binding_of_caller", ">= 0.6.8", :group => :development
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'jquery-rails'
gem 'rails-backbone'
gem "bootstrap-sass", "~> 2.3.0.0"
gem 'requirejs-rails'
gem 'ejs'
gem 'devise'
gem "better_errors", ">= 0.2.0", :group => :development
gem "binding_of_caller", ">= 0.6.8", :group => :development
gem 'color_routes'
gem 'gon'
では、展開を完了するには、どこから構成を開始する必要がありますか?
潜在的な情報:ここでRailscastsからカスタムレーキタスクを作成する方法を見ると、カスタムレーキタスクの実行時に同じエラーが発生し、ライアンは、カスタムタスクが=> :environment dependency
(〜4:15)を必要とするため、タスクがDBにアクセスできないと説明します映画の中で)Userクラスにアクセスします。プリコンパイルでは曲モデルにアクセスできないため、同じまたは類似の依存関係を?に提供するにはどうすればよいapplication.js file
ですか?
他の情報:
アセットパイプラインの仕組みはセッションごとであると理解しています(たとえば、のように入力すると<%= link_to 'Sign in', new_user_path %>
、railsはアセットパイプラインでそれらのパスを定義し、ユーザーに提供します。Backboneはクライアント側のレンダリングであるため、ページがレールサーバーから渡された後の画像とサウンドへのパスを知る必要があります。これを行う唯一の方法は、上記の要点であり、JSに「アセット」をバンドルします。これは同様のアプローチです。これによりgem 'gon'
、ページにグローバル変数が提供されます。もちろん、私は新しい根拠に基づいて再構築を開いていますが、dev
モードで動作するので、私も理解しようとしてproduction
います。