使用RVM Ruby 1.9.3-p194将一个非常基本的Rails 3.2.3试用站点部署到“生产”服务器(不是真的在生产中,谢天谢地!),我发现以下列出的命令都是如此这里:
╔══════════════════════════════════════╤═══╗
║ command issued │OK?║
╟──────────────────────────────────────┼───╢
║ bundle exec rails console │ N ║
║ bundle exec rails console production │ Y ║
║ bundle exec rails server │ Y ║
║ bundle exec rails server production │ N ║
╚══════════════════════════════════════╧═══╝
我的第一个问题:这是预期的吗?(我原本认为右栏中的模式应该是N-Y-N-Y。)
更多信息:bundle exec rails console
因服务器上未安装 sqlite3 gem的可理解原因而失败。但是,bundle exec rails server production
失败了一条不太容易理解的痕迹:
$ bundle exec rails server production
Exiting
/home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler.rb:63:in `require': cannot load such file -- rack/handler/production (LoadError)
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler.rb:63:in `try_require'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler.rb:16:in `get'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:269:in `server'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands/server.rb:59:in `start'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我的第二个问题:如何最好地解决此错误?
答案 0 :(得分:18)
您是否希望使用生产环境以生产模式启动服务器?
rails server -e production
rails控制台环境和rails服务器-e环境之间的语法差异有点像PITA
答案 1 :(得分:3)
如果控制台生产指定了环境,并且在服务器的情况下它指定了其他东西(可能是哪个服务器使用webrick /...).
因此,如果您想指定环境,请执行以下操作:
ENV=production rails server