首页 文章

为什么我'm getting “undefined local variable or method `rails_env'“?

提问于
浏览
1

在做的时候我正在接受 undefined local variable or method 'rails_env'

执行“cd# && RAILS_ENV =# bundle exec rake sunspot:solr:stop”

我不是一个大的capistrano或铁路专家 .

在deploy.rb我有

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"

在deploy / staging.rb上我有

set :rails_env, :staging

什么错过了?

2 回答

  • 0

    你应该使用 fetch 方法 . 所以,而不是 rails_env 使用:

    fetch(:rails_env)
    

    Here(或here)是更多细节 .

  • 3

    尝试用 Rails.env 替换 rails_env

相关问题