我有/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