我从头开始创建一个新的rails 4beta1应用程序(ruby 2.0),当我在开发模式下启动服务器时,它运行良好,但是当我尝试生产时却没有。
我已经尝试运行bundle exec rake assets:precompile RAILS_ENV=production
并在config.serve_static_assets
文件中将config/environments/production
更改为true但我仍然收到错误:
=> Booting WEBrick
=> Rails 4.0.0.beta1 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-04-03 11:53:46] INFO WEBrick 1.3.1
[2013-04-03 11:53:46] INFO ruby 2.0.0 (2013-02-24) [x86_64-darwin12.2.0]
[2013-04-03 11:53:46] INFO WEBrick::HTTPServer#start: pid=13848 port=3000
I, [2013-04-03T11:53:50.521162 #13848] INFO -- : Started GET "/" for 127.0.0.1 at 2013-04-03 11:53:50 +0100
F, [2013-04-03T11:53:50.695426 #13848] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/"):
actionpack (4.0.0.beta1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.0.0.beta1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0.beta1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0.beta1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0.beta1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
actionpack (4.0.0.beta1) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0.beta1) lib/rails/engine.rb:510:in `call'
railties (4.0.0.beta1) lib/rails/application.rb:96:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/jbatista/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/jbatista/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/jbatista/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
网页错误:
答案 0 :(得分:3)
在Rails 4.0中,由于技术原因,默认的Rails页面不适用于生产环境,这包括任何服务器(如heroku)。好消息是,当你开始添加控制器,设置路线等时,错误就会消失......
刚开始开发,你会没事的。
答案 1 :(得分:1)
看起来你需要在config/routes.rb
中定义根路由
MyApp::Application.routes.draw do
root :to => "MyApp#index"
end
其中MyApp
表示您的应用程序名称。
答案 2 :(得分:0)
在config/environments/production.rb
中,serve_static_assets应该为false,因为在生产中他们的服务器会处理它们。
config.serve_static_assets = false
此外,你不应该在生产中使用WEBrick,它只应该用于开发。例如,转而使用thin。
基本上,将gem 'thin'
添加到我们的Gemfile中。