本文介绍了NoMethodError:main:Object 的未定义方法“on"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试 bundle exec cap production deploy --trace 时,我收到一条错误消息:

deploy@h2540559:/www/apps/foodsoft$ bundle exec cap production deploy --trace** 调用生产(first_time)** 执行生产** 调用 load:defaults (first_time)** 执行 load:defaults** 调用 rvm:hook (first_time)** 执行 rvm:hook帽流产!NoMethodError:main:Object 的未定义方法on"/usr/local/rvm/gems/ruby-2.0.0-p643/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:17:in `block (2 levels) in <top(必填)>'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:248:in `call'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:248:in `block in execute'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:243:in `each'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:243:in `execute'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:187:in `block in invoke_with_call_chain'/usr/local/rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:180:in `invoke_with_call_chain'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:173:in `invoke'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/capistrano-3.2.1/lib/capistrano/dsl/task_enhancements.rb:12:in ‘block in after’/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:248:in `call'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:248:in `block in execute'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:243:in `each'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:243:in `execute'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:187:in `block in invoke_with_call_chain'/usr/local/rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:180:in `invoke_with_call_chain'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:173:in `invoke'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:150:in `invoke_task'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:106:in `each'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:106:in `block in top_level'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:115:in `run_with_threads'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:100:in `top_level'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:78:in `block in run'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:176:in `standard_exception_handling'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:75:in `run'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'/usr/local/rvm/gems/ruby-2.0.0-p643/gems/capistrano-3.2.1/bin/cap:3:in ‘’/usr/local/rvm/gems/ruby-2.0.0-p643/bin/cap:23:in `load'/usr/local/rvm/gems/ruby-2.0.0-p643/bin/cap:23:in `<main>'/usr/local/rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `eval'/usr/local/rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `<main>'任务:TOP =>房车:钩子

这是我的 gemfile:

# 一个示例 Gemfile来源https://rubygems.org"宝石导轨",'~>4.2'gem 'sass-rails'宝石咖啡轨"gem 'less-rails'gem 'uglifier', '>= 1.0.3'# 有关更多支持的运行时,请参阅 https://github.com/sstephenson/execjs#readmegem 'therubyracer',平台::ruby宝石'jquery-rails'宝石'select2-rails'宝石'rails_tokeninput'gem 'bootstrap-datepicker-rails'宝石'date_time_attribute'gem 'rails-assets-listjs', '0.2.0.beta.4' # 记得在更新时维护 list.*.js 插件和模板引擎gem 'i18n-js', '~>3.0.0.rc8'宝石'rails-i18n'宝石'mysql2'宝石虾"宝石'虾桌'gem 'haml-rails'宝石 'kaminari'宝石'simple_form'宝石'inherited_resources'gem 'localize_input', git: "git://github.com/bennibu/localize_input.git"宝石守护进程"gem 'twitter-bootstrap-rails', '~>2.2.8'gem '简单导航', '~>3.14.0' # 3.x 用于 simple_navigation_bootstrapgem '简单导航引导'宝石洗劫"宝石'acts_as_tree'gem 'rails-settings-cached'宝石'resque'gem 'whenever', require: false # 定义 cronjobs,参见 config/schedule.rb宝石'protected_attributes'宝石红宝石单位"宝石'attribute_normalizer'gem 'ice_cube', github: 'wvengen/ice_cube', 分支: 'issues/50-from_ical-rebased' # fork 直到合并宝石'recurring_select'宝石 'roo', '~>1.13.2'宝石电子表格"# 我们使用acts_as_versioned的git版本,需要将它包含在这个Gemfile中gem 'acts_as_versioned',github:'technoweenie/acts_as_versioned'宝石foodsoft_wiki",路径:插件/维基"gem 'foodsoft_messages',路径:'插件/消息'# 默认情况下未启用插件#gem 'foodsoft_uservoice',路径:'插件/用户语音'组:生产做宝石'exception_notification'结尾组:开发做宝石'sqlite3'宝石邮件捕手"gem '网络控制台', '~>2.0'# 允许使用`debugger` https://github.com/conradirwin/pry-rescue宝石撬救援"宝石'撬堆栈_资源管理器'# 更好的错误输出宝石'better_errors'宝石'binding_of_caller'# gem "rails-i18n-debug"# chrome 调试扩展 https://github.com/dejan/rails_panel宝石元请求"# 不使用适当的急切加载时获取信息宝石子弹"# 在日志中隐藏资产请求宝石'quiet_assets'# 使用 Capistrano 部署宝石 'capistrano', '~>3.2.0',要求:假gem 'capistrano-rvm',需要:falsegem 'capistrano-bundler','>= 1.1.0',需要:falsegem 'capistrano-rails',需要:false# 避免内容长度警告宝石薄"结尾组:开发,:测试做gem 'ruby-prof',需要:false结尾组:测试做gem 'rspec-rails'宝石 'factory_girl_rails'宝石伪造者"宝石水豚"# webkit 和 poltergeist 似乎还没有工作宝石硒网络驱动程序"宝石'database_cleaner'宝石'connection_pool'# 需要在 i18n-spec 或 rake 在测试环境中失败之前包含 rspec 组件gem 'rspec-core', '~>3.2'gem 'rspec-rerun'gem 'rspec-legacy_formatters'宝石'i18n-spec'# 代码覆盖gem 'simplecov',要求:falsegem '工作服',要求:false结尾

我的文件

# 加载 DSL 和设置阶段需要capistrano/设置"# 包括默认部署任务需要capistrano/deploy"# 包括来自 Gemfile 中其他 gem 的任务## 有关这些的文档,请参见例如:## https://github.com/capistrano/rvm# https://github.com/capistrano/rbenv# https://github.com/capistrano/chruby# https://github.com/capistrano/bundler# https://github.com/capistrano/rails#需要'capistrano/rvm'# 需要'capistrano/rbenv'# 需要 'capistrano/chruby'# 需要'capistrano/bundler'需要capistrano/rails/assets"需要'capistrano/rails/migrations'# 从`lib/capistrano/tasks' 加载自定义任务,如果你有任何定义的话.Dir.glob('lib/capistrano/tasks/*.{cap,rake}').each { |r|导入 r }

还有我的 deploy.rb

## Capistrano 3 部署配置## http://www.capistranorb.com/# https://semaphoreapp.com/blog/2013/11/26/capistrano-3-upgrade-guide.html# 可以从环境中更新的默认值set :branch, ENV["REVISION"] ||ENV["BRANCH_NAME"] ||掌握"# 你可能想改变这些set :application, 'foodsoft' # 应用程序名称(随便你)set :domain, 'biomio-giessen.de' # 主机set :user, 'deploy' # ssh 部署用户设置:keep_releases, 10设置:repo_url, 'git://github.com/foodcoops/foodsoft.git'set :deploy_to, "/www/apps/#{fetch :application}-#{fetch :stage}"# 更多可能没问题的设置设置:日志级别,:信息set :linked_files, %w{config/database.yml config/app_config.yml config/initializers/secret_token.rb config/initializers/session_store.rb}set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}# 假设所有内容都使用一台服务器,一个用户用于部署,一个用户用于 resque服务器获取(:域),用户:获取(:用户),角色:[:web,:app,:resque,:db]# 如果您使用 RVM,请取消注释 Capfile 中的行,并可选择取消注释 rvm 设置# 设置 :rvm_ruby_string, :local# 任务挂钩命名空间:部署做desc '重新启动应用程序'任务:重启做在角色(:应用程序),在::序列,等待:5做# 告诉 mod_passenger 重新加载应用程序执行 :touch, release_path.join('tmp/restart.txt')结尾结尾:restart, 'resque:restart' 之后之后:完成,部署:清理"# 见 lib/capistrano/tasks/plugins.cap#before 'bundler:install', 'enable_plugins:auto'结尾

有谁知道如何解决这个问题?

非常感谢,马克西

解决方案

我刚刚在运行一个包更新后遇到了同样的错误,没有更新任何主要版本,除了 Rake 到 11.从 capistrano 3.2.1 升级到3.4.0 帮我修好了!

when I try to bundle exec cap production deploy --trace I get an error message:

deploy@h2540559:/www/apps/foodsoft$ bundle exec cap production deploy --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke rvm:hook (first_time)
** Execute rvm:hook
cap aborted!
NoMethodError: undefined method `on' for main:Object
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:17:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:248:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:248:in `block in execute'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:243:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:243:in `execute'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:173:in `invoke'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/capistrano-3.2.1/lib/capistrano/dsl/task_enhancements.rb:12:in `block in after'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:248:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:248:in `block in execute'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:243:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:243:in `execute'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/task.rb:173:in `invoke'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:150:in `invoke_task'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:106:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:106:in `block in top_level'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:100:in `top_level'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:78:in `block in run'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/rake-11.1.1/lib/rake/application.rb:75:in `run'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/usr/local/rvm/gems/ruby-2.0.0-p643/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p643/bin/cap:23:in `load'
/usr/local/rvm/gems/ruby-2.0.0-p643/bin/cap:23:in `<main>'
/usr/local/rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => rvm:hook

Here is my gemfile:

# A sample Gemfile
source "https://rubygems.org"

gem "rails", '~> 4.2'
gem 'sass-rails'
gem 'coffee-rails'
gem 'less-rails'
gem 'uglifier', '>= 1.0.3'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby


gem 'jquery-rails'
gem 'select2-rails'
gem 'rails_tokeninput'
gem 'bootstrap-datepicker-rails'
gem 'date_time_attribute'
gem 'rails-assets-listjs', '0.2.0.beta.4' # remember to maintain list.*.js plugins and template engines on update
gem 'i18n-js', '~> 3.0.0.rc8'
gem 'rails-i18n'

gem 'mysql2'
gem 'prawn'
gem 'prawn-table'
gem 'haml-rails'
gem 'kaminari'
gem 'simple_form'
gem 'inherited_resources'
gem 'localize_input', git: "git://github.com/bennibu/localize_input.git"
gem 'daemons'
gem 'twitter-bootstrap-rails', '~> 2.2.8'
gem 'simple-navigation', '~> 3.14.0' # 3.x for simple_navigation_bootstrap
gem 'simple-navigation-bootstrap'
gem 'ransack'
gem 'acts_as_tree'
gem 'rails-settings-cached'
gem 'resque'
gem 'whenever', require: false # For defining cronjobs, see config/schedule.rb
gem 'protected_attributes'
gem 'ruby-units'
gem 'attribute_normalizer'
gem 'ice_cube', github: 'wvengen/ice_cube', branch: 'issues/50-from_ical-rebased' # fork until merged
gem 'recurring_select'
gem 'roo', '~> 1.13.2'
gem 'spreadsheet'

# we use the git version of acts_as_versioned, and need to include it in this Gemfile
gem 'acts_as_versioned', github: 'technoweenie/acts_as_versioned'
gem 'foodsoft_wiki', path: 'plugins/wiki'
gem 'foodsoft_messages', path: 'plugins/messages'

# plugins not enabled by default
#gem 'foodsoft_uservoice', path: 'plugins/uservoice'


group :production do
  gem 'exception_notification'
end

group :development do
  gem 'sqlite3'
  gem 'mailcatcher'
  gem 'web-console', '~> 2.0'

  # allow to use `debugger` https://github.com/conradirwin/pry-rescue
  gem 'pry-rescue'
  gem 'pry-stack_explorer'

  # Better error output
  gem 'better_errors'
  gem 'binding_of_caller'
  # gem "rails-i18n-debug"
  # chrome debugging extension https://github.com/dejan/rails_panel
  gem 'meta_request'

  # Get infos when not using proper eager loading
  gem 'bullet'

  # Hide assets requests in log
  gem 'quiet_assets'

  # Deploy with Capistrano
  gem 'capistrano', '~> 3.2.0', require: false
  gem 'capistrano-rvm', require: false
  gem 'capistrano-bundler', '>= 1.1.0', require: false
  gem 'capistrano-rails', require: false
  # Avoid having content-length warnings
  gem 'thin'
end

group :development, :test do
  gem 'ruby-prof', require: false
end

group :test do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'faker'
  gem 'capybara'
  # webkit and poltergeist don't seem to work yet
  gem 'selenium-webdriver'
  gem 'database_cleaner'
  gem 'connection_pool'
  # need to include rspec components before i18n-spec or rake fails in test environment
  gem 'rspec-core', '~> 3.2'
  gem 'rspec-rerun'
  gem 'rspec-legacy_formatters'
  gem 'i18n-spec'
  # code coverage
  gem 'simplecov', require: false
  gem 'coveralls', require: false
end

my capfile

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails
#
 require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
# require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.{cap,rake}').each { |r| import r }

and also my deploy.rb

#
# Capistrano 3 deployment configuration
#
#   http://www.capistranorb.com/
#   https://semaphoreapp.com/blog/2013/11/26/capistrano-3-upgrade-guide.html

# defaults that can be updated from the environment
set :branch,              ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"

# you probably want to change these
set :application,         'foodsoft'            # application name (whatever you like)
set :domain,              'biomio-giessen.de' # host
set :user,                'deploy'              # ssh deploy user
set :keep_releases,       10
set :repo_url,            'git://github.com/foodcoops/foodsoft.git'
set :deploy_to,            "/www/apps/#{fetch :application}-#{fetch :stage}"

# more settings which are probably ok
set :log_level,           :info
set :linked_files,        %w{config/database.yml config/app_config.yml config/initializers/secret_token.rb config/initializers/session_store.rb}
set :linked_dirs,         %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

# assuming one server for everything, with one user for deploy and one for resque
server fetch(:domain), user: fetch(:user), roles: [:web, :app, :resque, :db]

# if you use RVM, uncomment the line in Capfile, and optionally uncomment rvm settings
# set :rvm_ruby_string,     :local

# task hooks
namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # tell mod_passenger to reload the application
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :restart, 'resque:restart'

  after :finishing, 'deploy:cleanup'

  # see lib/capistrano/tasks/plugins.cap
  #before 'bundler:install', 'enable_plugins:auto'

end

Does anyone know how to fix this?

Thank you very much,Maxi

解决方案

I had the same error just now after running a bundle update, no major versions were updated, except for Rake to 11. An upgrade from capistrano 3.2.1 to 3.4.0 fixed it for me!

这篇关于NoMethodError:main:Object 的未定义方法“on"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:57