0

我从头开始创建了一个新的 rails 4beta1 应用程序(ruby 2.0),当我在开发模式下启动 de 服务器时它运行良好,但是当我在生产环境中尝试时却没有。

我已经尝试在文件中运行bundle exec rake assets:precompile RAILS_ENV=production并将其更改config.serve_static_assets为 true,config/environments/production但仍然出现错误:

=> 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'

网页错误:

在此处输入图像描述

4

3 回答 3

3

在 Rails 4.0 中,由于技术原因,默认的 Rails 页面在生产环境中不起作用,这包括任何服务器(如 heroku)。好消息是,当您开始添加控制器、设置路由等时,错误就会消失......

刚开始开发,你会没事的。

于 2013-04-03T21:54:22.337 回答
1

看起来你也需要像这样定义根config/routes.rb 路由

MyApp::Application.routes.draw do
root :to => "MyApp#index"
end

其中MyApp是指您的应用程序名称。

于 2013-04-03T14:52:08.970 回答
0

config/environments/production.rbserve_static_assets 中应该是假的,因为在生产中他们的服务器会处理它们。

config.serve_static_assets = false

此外,您不应该在生产中使用 WEBrick,它应该只在开发中使用。以瘦身为例。

在此处输入图像描述

基本上,添加gem 'thin'到我们的 Gemfile。

于 2013-04-03T14:27:08.110 回答