2
votes

I'm getting undefined local variable or method 'rails_env'when doing

execute "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:stop"

I'm not a big capistrano or rails expert.

On deploy.rb I have

namespace :solr do
  desc "start solr"
  task :start do
    on roles(:app) do
      execute "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:start"
    end
  end

  desc "stop solr"
  task :stop do
    on roles(:app) do
      execute "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:stop"
    end
  end

  desc "reindex the whole database"
  task :reindex do
    on roles(:app) do
      invoke 'solr:stop'
      execute "rm -rf #{shared_path}/solr/data/*"
      invoke 'solr:start'
      execute "cd #{current_path} && RAILS_ENV=#{rails_env} d"
    end
  end

  desc "Symlink in-progress deployment to a shared Solr index"
  task :symlink do
    on roles(:app) do
      execute "ln -s #{shared_path}/solr/data/ #{release_path}/solr/data"
      execute "ln -s #{shared_path}/solr/pids/ #{release_path}/solr/pids"
      invoke 'solr:reindex'
    end
  end
end

after "deploy:finishing", "solr:symlink"

And on deploy/staging.rb I have

 set :rails_env, :staging

What's missed?

2

2 Answers

4
votes

You should use fetch method. So, instead of rails_env use:

fetch(:rails_env)

Here (or here) is more details.

0
votes

Try replacing rails_env with Rails.env