以前正在运行的Rails 3.1应用程序现在无法部署。 Capistrano deploy:assets:precompile
任务遇到错误“Could not find table 'users'
”。
我已使用rake --trace
将此错误修改为users
模型中新添加的命名范围:
scope :find_by_skill_offered, lambda { |skill_id|
joins(:skills).where("user_skills.offered = ? AND skills.id = ?", 'true', skill_id)
}
在我看来,rake任务可能在数据库链接之前尝试执行lambda,因此失败。
这听起来像this problem with factory_girl的类似问题,即代码在数据库存在之前执行,但我无法理解为什么lambda会在实际调用之前执行。
堆栈跟踪也显示了那里的Devise路由的构造,所以也许它与此相关,但是路由代码作为deploy:assets:precompile
的一部分运行似乎很奇怪,或者我错过了一些关于如何管道有效吗?
提前致谢。
更新
本地rake assets:precompile
也会出现这种情况(我通常只在服务器上构建资产)。
完整错误输出和跟踪:
* 18:47:58 == Currently executing `deploy:assets:precompile'
* executing "cd /home/backscratchers/development/backscratchers/releases/20111010174747 && rake --trace RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["87.106.100.151"]
[87.106.100.151] executing command
*** [err :: 87.106.100.151] ** Invoke assets:precompile (first_time)
*** [err :: 87.106.100.151] ** Execute assets:precompile
*** [err :: 87.106.100.151] ** Invoke environment (first_time)
*** [err :: 87.106.100.151] ** Execute environment
*** [err :: 87.106.100.151] rake aborted!
*** [err :: 87.106.100.151] Could not find table 'users'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:387:in `table_structure'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:270:in `columns'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `block (2 levels) in initialize'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:92:in `block in initialize'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:706:in `yield'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:706:in `default'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:706:in `columns'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:722:in `column_names'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:735:in `column_methods_hash'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1101:in `all_attributes_exists?'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:886:in `respond_to?'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/named_scope.rb:193:in `valid_scope_name?'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/named_scope.rb:175:in `scope'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/releases/20111010174747/app/models/user.rb:6:in `<class:User>'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/releases/20111010174747/app/models/user.rb:1:in `<top (required)>'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:225:in `load_dependency'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:348:in `require_or_load'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:489:in `load_missing_constant'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:181:in `block in const_missing'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `each'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `const_missing'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/inflector/methods.rb:124:in `block in constantize'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/inflector/methods.rb:123:in `each'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/inflector/methods.rb:123:in `constantize'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:528:in `block in initialize'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:550:in `yield'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:550:in `default'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:550:in `[]'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:595:in `constantize'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise.rb:259:in `get'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise/mapping.rb:101:in `to'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise/mapping.rb:96:in `modules'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise/mapping.rb:113:in `routes'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise/mapping.rb:82:in `initialize'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise.rb:289:in `new'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise.rb:289:in `add_mapping'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise/rails/routes.rb:191:in `block in devise_for'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise/rails/routes.rb:190:in `each'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/devise-1.4.5/lib/devise/rails/routes.rb:190:in `devise_for'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/releases/20111010174747/config/routes.rb:20:in `block in <top (required)>'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:257:in `instance_exec'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:257:in `eval_block'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:234:in `draw'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/releases/20111010174747/config/routes.rb:1:in `<top (required)>'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `block in load'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:225:in `load_dependency'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/routes_reloader.rb:29:in `block in load_paths'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/routes_reloader.rb:29:in `each'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/routes_reloader.rb:29:in `load_paths'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/routes_reloader.rb:13:in `reload!'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/routes_reloader.rb:7:in `block in initialize'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/file_update_checker.rb:32:in `call'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/finisher.rb:63:in `block (2 levels) in <module:Finisher>'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/finisher.rb:64:in `call'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/finisher.rb:64:in `block in <module:Finisher>'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `instance_exec'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `run'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:50:in `block in run_initializers'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `each'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `run_initializers'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application.rb:92:in `initialize!'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/releases/20111010174747/config/environment.rb:5:in `<top (required)>'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application.rb:78:in `require_environment!'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application.rb:189:in `block (2 levels) in initialize_tasks'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
*** [err :: 87.106.100.151] /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
*** [err :: 87.106.100.151] /home/backscratchers/development/backscratchers/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/sprockets/assets.rake:11:in `block (2 levels) in <top (required)>'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
*** [err :: 87.106.100.151] /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
*** [err :: 87.106.100.151] /usr/local/rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
*** [err :: 87.106.100.151] Tasks: TOP => environment
答案 0 :(得分:0)
我通过用类方法替换lambda函数来解决这个问题:
def self.find_by_skill_offered(skill_id)
joins(:skills).where("user_skills.offered = ? AND skills.id = ?", 'true', skill_id)
}
这似乎是Rails 3.1及更高版本的首选方法。
如果它是Devise中的一个错误,我创建了an issue on GitHub,显然使用像find_by_*
这样的名字可能会搞砸了。
我喜欢使用与Rails自动生成的查找函数相同的命名(虽然它实际上是find_all_by_*
,因为它返回一个数组),但由于这似乎是狡猾的,也许应该避免。
很抱歉没有对错误做出明确答案。