Rails 5:使用流浪者在本地主机上启动应用程序时超时



我正试图将我的应用程序从Cloud 9移动到Localhost。这就是我迄今为止所做的:

  1. 安装了Vagrant 1.9.1和Virtualbox 5.1.12。在我的Windows 10上64位
  2. 安装了Vagrant的Ubuntu 16.04.1和Postgresql 9.5
  3. 使用rails db:setup从我的架构创建DB

在终端中,我可以用rails server -b 0.0.0.0启动Rails服务器,并且它正确启动:

=> Booting Puma
=> Rails 5.0.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.2 (ruby 2.3.3-p222), codename: Sleepy Sunday Serenity
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

当我打开http://localhost:3000/时,它会给我超时错误Rack::Timeout::RequestTimeoutException in LandingController#index

并指向我的landing/index.html.erb中的线,如下所示:

<img src="<%= image_path('landing/laptop.png') %>" alt="laptop"/>

在终端中,我看到这样的消息:

Rack::Timeout::RequestTimeoutException (Request ran for longer than 20000ms):
app/views/landing/index.html.erb:51:in `_app_views_landing_index_html_erb___1903502845453706848_40657680'
app/controllers/landing_controller.rb:6:in `index'
Rendering /home/ubuntu/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
Rendering /home/ubuntu/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered /home/ubuntu/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (11.6ms)
Rendering /home/ubuntu/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered /home/ubuntu/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.2ms)
Rendering /home/ubuntu/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered /home/ubuntu/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.3ms)
Rendered /home/ubuntu/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (46.7ms)
source=rack-timeout id=989422929f6047c15c931fac986f4ae0 timeout=20000ms service=22077ms state=completed

资产已经到位,就像之前在Cloud 9中一样-我没有做任何更改。我以为是链轮的问题,所以我重新安装了它,但运气不好,错误一直存在。

请问我该怎么解决谢谢!

更新

控制器没有什么特别之处:

class LandingController < ApplicationController
skip_before_action :logged_in_user, only: [:index]
skip_before_action :get_role, only: [:index]
def index
render layout: 'empty'
end
end

更新2

即使我将我的应用程序移动到RailsInstaller for Windows,这个错误仍然存在,所以我认为Vagrant在我的情况下不应受到指责。你知道我做错了什么吗?在我看来,有一些事情与我从Cloud 9复制+粘贴的应用程序有关,我在那里有缓存。

不确定为什么它在您的情况下不起作用,但我们发现Rack::Timeout在开发中会引起足够多的麻烦,因此我们只禁用它。您可以通过在开发模式中将超时设置为0来实现这一点。只需添加一个包含以下内容的config/initializers/rack_timeout.rb文件:

Rack::Timeout.service_timeout = Rails.env.development? ? 0 : 25

是否会更改<img src="<%= image_path('landing/laptop.png') %>" alt="laptop"/>

<%= image_tag('landing/laptop.png') %>工作?

这是文档的链接

最新更新