2011-06-21 79 views
0

我想RoR中創建一個非常簡單的Hello,world程序,但是當我去查看URL http://localhost:3000/say/hello我收到錯誤消息No route matches: "say/hello"沒有路由匹配「說/你好」時,路由存在

當我開始在軌服務器我得到警告此消息散佈:

=> Booting WEBrick 
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000 
=> Call with -d to detach 
=> Ctrl-C to shutdown server 
[2011-06-20 20:02:44] INFO WEBrick 1.3.1 
[2011-06-20 20:02:44] INFO ruby 1.9.2 (2011-02-18) [i686-linux] 
[2011-06-20 20:02:44] WARN TCPServer Error: Address already in use - bind(2) 
Exiting 
/home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:73:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE) 
    from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:73:in `new' 
    from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:73:in `block in create_listeners' 
    from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:70:in `each' 
    from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:70:in `create_listeners' 
    from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:74:in `listen' 
    from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:62:in `initialize' 
    from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:24:in `initialize' 
    from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/handler/webrick.rb:10:in `new' 
    from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/handler/webrick.rb:10:in `run' 
    from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:217:in `start' 
    from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/server.rb:65:in `start' 
    from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:30:in `block in <top (required)>' 
    from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap' 
    from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

我開始:導軌產生控制器問好再見 列出路線得到「說/你好」

另外:我'm h這可能與此問題有關。當我去寫一些基本的HTML中,這顯然是列爲現有的文件之一,我得到這個:

我寫這篇文章:

~/work/demo$ /app/views/say/hello.html.erb 

得到的回報此錯誤消息:

bash: /app/views/say/hello.html.erb: No such file or directory 

這是怎麼回事?我直接從Agile Development with Rails獲得這些說明,它非常簡單。我不明白髮生了什麼事。

+1

[路由不存在時匹配「say/hello」路由存在時可能的重複](http://stackoverflow.com/questions/6418549/no-route-matches-say-hello-when-route-exists) –

回答

1
[2011-06-20 20:02:44] WARN TCPServer Error: Address already in use - bind(2) 

您已經有一臺服務器(或其它)運行在您的服務器應該運行的端口上。因此,您認爲正在運行的代碼(您說有問題的路由)實際上沒有運行。一旦你關閉了另一個進程(可能是以前運行的rails服務器?),你可以啓動正確的進程並確保它實際上具有該進程。

+0

谷歌搜索錯誤消息。找到關於如何殺死幻影服務器的說明。現在一切都很順利 – Bodhidarma

1

在啓動rails時出現的錯誤表明服務器上已經有一臺運行在端口3000上的服務器(顯然,該服務器對「say/hello」路由沒有任何意義)。關閉一個,然後再試一次。

0

第二個錯誤是因爲從bash路徑/進入根目錄。試試:

cat app/views/say/hello.html.erb 
0

我面臨着類似的問題。在我的情況下$ rails server命令後,我無法在終端中使用ctrl-C關閉服務器。當我在終端按ctrl-C時什麼也沒有發生。

當我重新打開另一個終端上的項目,然後再次運行它,我得到以下信息:


系統 - 產品名稱:〜/ testapp $軌小號 =>引導的WEBrick => Rails 3.1.0.rc4應用程序開始http://0.0.0.0:3000 開發=>使用-d分開呼叫 => Ctrl-C關機服務器 [2011-06-30 16:41:23] INFO WEBrick 1.3.1 [ 2011-06-30 16:41:23] INFO ruby​​ 1.9.2(2011-02-18)[x86_64-linux] [2011-06-30 16:41:23] WARN TCPServer Er ror:已經在使用的地址 - 綁定(2) 退出 /.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:73:in initialize': Address already in use - bind(2) (Errno::EADDRINUSE) ls.rb:73:in新的' bubble/.rvm/rubies/ruby​​-1.9.2-p180/lib/ruby​​/1.9.1/webrick/utils.rb:73:在block in create_listeners' from bubble/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:70:in每個' from bubble/.rvm/rubies/ruby​​-1.9.2- P180/lib中/紅寶石/ 1.9.1 /的WEBrick/utils的。rb:70:在create_listeners' from bubble/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:74:in裏監聽' from bubble/.rvm/rubies/ruby​​-1.9.2-p180/lib/ruby​​/1.9.1/webrick/server.rb:62:在initialize' from bubble/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:24:in從bubble /初始化' 。 rvm/gems/[email protected]/gems/rack-1.3.0/lib/rack/handler/webrick.rb:10:在new' from bubble/.rvm/gems/[email protected]/gems/rack-1.3.0/lib/rack/handler/webrick.rb:10:in下運行' from bubble/.rvm/gems/ruby​​-1.9 .2-p180 @ rails31/gems/rack-1.3.0/lib/rack/server.rb:265:在start' from bubble/.rvm/gems/[email protected]/gems/railties-3.1.0.rc4/lib/rails/commands/server.rb:70:in開始' from bubble /.rvm/gems/[email protected]/gems/ railties-3.1.0.rc4/lib/rails/commands.rb:54:在block in <top (required)>' from bubble/.rvm/gems/[email protected]/gems/railties-3.1.0.rc4/lib/rails/commands.rb:49:in中點擊' from bubble /.rvm/gems/[email protected]/gems/railties-3.1.0.rc4 /lib/rails/commands.rb:49:in <top (required)>' from script/rails:6:in要求' from script/rails:6:in''


實質上,我必須每次從系統監視器中終止進程。這可以治癒嗎?

+0

我的工作是按Ctrl + z然後鍵入「fg」(當然沒有引號)。這應該會終止服務器。 – bruno077

+0

我想要的不是每次都殺死進程。確定終端不接受「Ctrl + C」掛機關閉服務器的原因。嘗試搜索網絡,但大多數人都在談論殺死開關。 – marvindanig

+1

從我發現它是一個Rails的bug,一直存在約3.0.5〜。在這裏,一些信息http://stackoverflow.com/questions/5891567/cant-stop-webrick-1-3-1-with-ctrl-c-on-ubuntu-11-04 – bruno077

0

在Mac上,鍵入您的終端如下:

lsof | grep IPv4

在linux

lsof|grep 3000我想。

找到以'ruby'開頭的lione並記下旁邊的數字。

讓我們說數字是你端以下1234類型:

kill -9 1234 

,你應該是正確的。請記住使用control-c退出WEBrick!

相關問題