Search code examples
ruby-on-railsrubycapistranodigital-ocean

Undefined method `namespace' in Capistrano ( Rails )


This is my first time to deploy a rails app in DigitalOcean, but I'm having a problem in deploying the application. When I tried to run the cap production deploy or bundle exec cap deploy:setup I got an error of :

/usr/local/rvm/gems/ruby-2.2.0/gems/capistrano-bundler-1.1.4/lib/capistrano/tasks/bundler.cap:1:in `<top (required)>': undefined method `namespace' for main:Object (NoMethodError)

this is my deploy.rb

set :application, "myapp.com"
set :repository,  "[email protected]:myapp.git"

set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :user, 'user'
set :use_sudo, false
set :deploy_to, "/home/user/video-benta"
set :deploy_via, :remote_cache

role :web, "myapp.com"                          # Your HTTP server, Apache/etc
role :app, "myapp.com"                          # This may be the same as your `Web` server
role :db,  "myapp", :primary => true # This is where Rails migrations will run
#role :db,  "your slave db-server here"

# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

# If you are using Passenger mod_rails uncomment this:
after "deploy", "deploy:bundle_gems"
after "deploy:bundle_gems", "deploy:restart"

 namespace :deploy do
   task :bundle_gems do
        run "cd #{deploy_to}/current && bundle install vendor/gems"
   end
   task :start do ; end
   task :stop do ; end
   task :restart, :roles => :app, :except => { :no_release => true } do
     run "touch #{File.join(current_path,'tmp','restart.txt')}"
   end
 end

Capfile ( Update )

load 'deploy'
# Uncomment if you are using Rails' asset pipeline
    # load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
require 'capistrano/bundler'
require 'capistrano/rails'

# If you are using rvm add these lines:
require 'capistrano/rvm'
 set :rvm_type, :user
 set :rvm_ruby_version, '2.2.0p0'

Solution

  • You are trying to use different Capistrano extensions incompatible with your Capistrano version. Your Capistrano version is 2.x (detected by format of your Capfile), but capistrano/bundler for example is a extension for Capistrano 3.x.

    Just use Capistrano 3 (if possible) and compatible extensions.