【问题标题】:Hartl Rails tutorial chapter 2, "hello world" isn't shown in http://localhost:3000Hartl Rails 教程第 2 章,“hello world”未显示在 http://localhost:3000
【发布时间】:2016-11-19 09:57:00
【问题描述】:

我正在关注 M. Hartl 的 Ruby On Rails 教程的每一步,但一直停留在第 2 章(“Hello world”)。我在application_controller.rb改了代码:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  def hello
      render html: "hello, world!"
  end

end

还有routes.rb 到:

Rails.application.routes.draw do
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  root 'application#hello'
end

但我的http://localhost:3000 页面仍然是空白的。我正在使用带有 Rails 版本 5.0.0.1 和 Ruby 2.2.4p230 的 Postgres。

__

编辑1

我还用&lt;h1&gt;HELLO WORLD&lt;/h1&gt; 创建了public/index.html,消息显示在页面上

__

编辑2

事实证明,您只需在对 routes.rb 进行任何更改后重新启动服务器

【问题讨论】:

  • 我刚刚在我的本地机器上启动了toyapp,并进行了您的确切更改并且它有效。 development.log 说什么?尝试渲染 localhost:3000 时检查 /log/development.log

标签: ruby-on-rails ruby postgresql


【解决方案1】:

应该是的

root to: "application#hello"

【讨论】:

【解决方案2】:

您的路线需要更改以包含to:

Rails.application.routes.draw do
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  root to: 'application#hello'
end

【讨论】:

  • 令人着迷...... to: 不应该是必要的 - 它只是你所拥有的东西的别名。当您弄清楚时,我很想听听解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多