2016-11-18 23 views
2

我遵循M. Hartl的Ruby On Rails教程的每一步,但仍停留在第2章(「Hello world」 )。我在application_controller.rb改變了代碼:Hartl Rails教程第2章「hello world」未在http:// localhost:3000中顯示

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。

__

EDIT1

而且我創建public/index.html<h1>HELLO WORLD</h1>,消息

頁面上顯示

__

EDIT2

原來你需要的是後重新啓動服務器在routes.rb

中作出任何更改
+1

我剛剛紡我的本地機器上的'toyapp',並提出您的具體變化和它的工作。 development.log是什麼意思?檢查 /log/development.log當你嘗試渲染http:// localhost:3000 – CDub

回答

2

它需要需要

root to: "application#hello" 
+0

沒有幫助,但是感謝嘗試 – taniamasania

+0

根據[Rails Guide](http: //guides.rubyonrails.org/routing.html#using-root) – spickermann

1

你的路線,改爲包括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 
+0

沒有幫助,但感謝嘗試 – taniamasania

+0

令人着迷......「to:'不應該是必要的 - 雖然 - 它只是你的別名有。當你想出解決方案時,我很樂意聽到解決方案。 – CDub

相關問題