新手问题 新手求助,诡异的问题新建的 rails3.2.11 项目在 production 下报错,在 development 下正常

sunluan · 2013年01月12日 · 最后由 tiseheaini 回复于 2013年01月12日 · 3952 次阅读

操作系统 win 7 ruby 1.9.3 rails 3.2.11 执行过程: rails new blog rake db:create rails server 可以看到 welcome aboard rails server -e production 页面内容是:

The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved. 命令行下的信息: D:\workspace\railsDemo\t1>rails s -e production => Booting WEBrick => Rails 3.2.11 application starting in production on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2013-01-12 00:16:44] INFO WEBrick 1.3.1 [2013-01-12 00:16:44] INFO ruby 1.9.3 (2012-11-10) [i386-mingw32] [2013-01-12 00:16:44] INFO WEBrick::HTTPServer#start: pid=8804 port=3000 Started GET "/" for 127.0.0.1 at 2013-01-12 00:16:47 +0800 Connecting to database specified by database.yml

ActionController::RoutingError (No route matches [GET] "/"): actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:21:in call' actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:inc all' railties (3.2.11) lib/rails/rack/logger.rb:32:in call_app' railties (3.2.11) lib/rails/rack/logger.rb:16:inblock in call' activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in tagged' railties (3.2.11) lib/rails/rack/logger.rb:16:incall' actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in call' rack (1.4.3) lib/rack/methodoverride.rb:21:incall' rack (1.4.3) lib/rack/runtime.rb:17:in call' activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in call' rack (1.4.3) lib/rack/lock.rb:15:in call' rack-cache (1.2) lib/rack/cache/context.rb:136:inforward' rack-cache (1.2) lib/rack/cache/context.rb:245:in fetch' rack-cache (1.2) lib/rack/cache/context.rb:185:inlookup' rack-cache (1.2) lib/rack/cache/context.rb:66:in call!' rack-cache (1.2) lib/rack/cache/context.rb:51:incall' railties (3.2.11) lib/rails/engine.rb:479:in call' railties (3.2.11) lib/rails/application.rb:223:incall' rack (1.4.3) lib/rack/content_length.rb:14:in call' railties (3.2.11) lib/rails/rack/log_tailer.rb:17:incall' rack (1.4.3) lib/rack/handler/webrick.rb:59:in service' d:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:138:inservice' d:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:94:in run' d:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:inblock in start_thread'

Started GET "/favicon.ico" for 127.0.0.1 at 2013-01-12 00:16:48 +0800

ActionController::RoutingError (No route matches [GET] "/favicon.ico"): actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:21:in call' actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:inc all' railties (3.2.11) lib/rails/rack/logger.rb:32:in call_app' railties (3.2.11) lib/rails/rack/logger.rb:16:inblock in call' activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in tagged' railties (3.2.11) lib/rails/rack/logger.rb:16:incall' actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in call' rack (1.4.3) lib/rack/methodoverride.rb:21:incall' rack (1.4.3) lib/rack/runtime.rb:17:in call' activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in call' rack (1.4.3) lib/rack/lock.rb:15:in call' rack-cache (1.2) lib/rack/cache/context.rb:136:inforward' rack-cache (1.2) lib/rack/cache/context.rb:245:in fetch' rack-cache (1.2) lib/rack/cache/context.rb:185:inlookup' rack-cache (1.2) lib/rack/cache/context.rb:66:in call!' rack-cache (1.2) lib/rack/cache/context.rb:51:incall' railties (3.2.11) lib/rails/engine.rb:479:in call' railties (3.2.11) lib/rails/application.rb:223:incall' rack (1.4.3) lib/rack/content_length.rb:14:in call' railties (3.2.11) lib/rails/rack/log_tailer.rb:17:incall' rack (1.4.3) lib/rack/handler/webrick.rb:59:in service' d:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:138:inservice' d:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:94:in run' d:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:inblock in start_thread'

到 bitnami 下载 rubystack,试了一下也是这种情况

装个 linux 虚拟机在里面再试试有没有问题

ActionController::RoutingError (No route matches [GET] "/"): 贴出 config/routes.rb 文件看看

刚才又试了一下注释了 production.rb 的下面几行就没问题了 # Disable Rails's static asset server (Apache or nginx will already do this) #config.serve_static_assets = false

# Compress JavaScripts and CSS #config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed #config.assets.compile = false

# Generate digests for assets URLs #config.assets.digest = true

#3 楼 @tiseheaini config/routes.rb是空的, 就是 rails new blog 新建项目 rails s 正常可以看到 welcome aboard rails s -e production 浏览器页面内容如下:

#5 楼 @sunluan 那你在项目里面执行 rake routes,有内容输出吗??

#7 楼 @sunluan 没有路由信息,肯定会报错,你需要指定路由信息 具体点例子 在 guides 中讲的很详细 http://guides.ruby-china.org/getting_started.html

#8 楼 @tiseheaini 哪为什么 rails s -e development,可以正常访问 127.0.0.1:3000

我想你应该没有删除 public/index.html 而且也没有定义路由,按照 guides 走一遍应该就明白了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号