1

/config/initializers/redis.rbがあります:

if Rails.env == "development"
  $redis = Redis.new(:host => 'localhost', :port => 6379)
elsif Rails.env == "test"
  $redis = Redis.new(:host => 'localhost', :port => 6379)
elsif Rails.env == "production"
  uri = URI.parse(ENV["REDISTOGO_URL"])
  REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
end

明らかに、アプリをローカルで実行すると、REDISTOGO_URL未定義です。

これを考えると、どうすればrails server -e production仕事をすることができますか?

を実行するには、本番環境にローカルでアクセスする必要がありますRAILS_ENV=production bundle exec rake assets:precompile

現在、次のエラーが発生します。

$ RAILS_ENV=production bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/steven/.rvm/rubies/ruby-1.9.3-p286/bin/ruby /Users/steven/.rvm/gems/ruby-1.9.3-p286/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
rake aborted!
bad URI(is not URI?): 
/Users/steven/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in `split'
/Users/steven/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in `parse'
/Users/steven/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in `parse'
/Users/steven/Dropbox/testivate/config/initializers/resis.rb:6:in `<top (required)>'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `block in load'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/engine.rb:587:in `each'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/engine.rb:587:in `block in <class:Engine>'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/steven/Dropbox/testivate/config/environment.rb:6:in `<top (required)>'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/application.rb:103:in `require_environment!'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.9/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/steven/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.9/lib/sprockets/assets.rake:93:in `block (2 levels) in <top (required)>'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/steven/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/Users/steven/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.9/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/steven/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/bin/rake:23:in `load'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/bin/rake:23:in `<main>'
Tasks: TOP => environment
rake aborted!
Command failed with status (1): [/Users/steven/.rvm/rubies/ruby-1.9.3-p286/...]
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `call'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `sh'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `sh'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/file_utils.rb:80:in `ruby'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `ruby'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.9/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.9/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.9/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/steven/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/bin/rake:23:in `load'
/Users/steven/.rvm/gems/ruby-1.9.3-p286/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile
4

1 に答える 1

0

コメントでbimsapiが言及しているように、簡単な方法は実行することです

export REDISTOGO_URL='redis://localhost:6379'

コマンドラインで、再起動するときのためにシェル設定に入れますか?

別の方法は、存在しない場合に作成することです。

例えば/

ENV["REDISTOGO_URL"] ||= 'redis://localhost:6379' if Rails.env.production? 

また、上記のクエリでは、条件付きロジックが少し場違いに見えます。

条件を完全に削除して、代わりにこれを実行したい場合がありますか?:

ENV["REDISTOGO_URL"] ||= 'redis://localhost:6379'
uri = URI.parse(ENV["REDISTOGO_URL"])
$redis = REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

HTH?

編集:Rails環境変数の構成でこれを見ただけです- http://railsapps.github.com/rails-environment-variables.html

于 2012-12-13T14:58:45.783 に答える