2010-10-20 68 views
0

我剛剛升級到Rails 3,並決定採用虛擬/沙箱應用程序進行旋轉。奇怪的是我似乎無法獲得任何路線上班!爲什麼這個基本的Rails 3路線不工作?

這裏是我的問題:

[[email protected]:Dev]$rails new TestApp 
     create 
     create README 
     create Rakefile 
     ... 
[[email protected]:Dev]$cd TestApp/ 
[[email protected]:TestApp]$rails g scaffold widget name:text 
     invoke active_record 
     create db/migrate/20101020115518_create_widgets.rb 
     create app/models/widget.rb 
     ... 
[[email protected]:TestApp]$rake db:migrate 
(in /Users/cobychapple/Dev/TestApp) 
== CreateWidgets: migrating ================================================== 
-- create_table(:widgets) 
    -> 0.0015s 
== CreateWidgets: migrated (0.0016s) ========================================= 

[[email protected]:TestApp]$rake routes 
(in /Users/cobychapple/Dev/TestApp) 
    widgets GET /widgets(.:format)   {:action=>"index", :controller=>"widgets"} 
    widgets POST /widgets(.:format)   {:action=>"create", :controller=>"widgets"} 
new_widget GET /widgets/new(.:format)  {:action=>"new", :controller=>"widgets"} 
edit_widget GET /widgets/:id/edit(.:format) {:action=>"edit", :controller=>"widgets"} 
    widget GET /widgets/:id(.:format)  {:action=>"show", :controller=>"widgets"} 
    widget PUT /widgets/:id(.:format)  {:action=>"update", :controller=>"widgets"} 
    widget DELETE /widgets/:id(.:format)  {:action=>"destroy", :controller=>"widgets"} 

[[email protected]:TestApp]$rails s -d 
=> Booting WEBrick 
=> Rails 3.0.1 application starting in development on http://0.0.0.0:3000 
[[email protected]:TestApp]$ 

所以,現在我頭就到我的瀏覽器,並訪問http://localhost:3000/widgets

Rails的說: 路由錯誤:沒有路由匹配 「/小工具」

我不要理解rake路由如何顯示路由存在,然後服務器就不會匹配它。我已經搜索了一大堆,似乎有一些人在軌道3中的路由問題,但沒有一個顯然是我得到的基本。我肯定我在路上錯過了一些小小的東西,但我不能爲了我的生活而弄明白!有什麼建議麼?

我的routes.rb文件只是什麼腳手架生成+文檔註釋:

TestApp::Application.routes.draw do 
    resources :widgets 

    # The priority is based upon order of creation: 
    # skip the rest of the comments... 
end 
+0

HAV你的文件app /控制器/ widgets_controller.rb? – shingara 2010-10-20 12:18:58

+0

我做了和你一樣的步驟,它的工作沒有問題。奇怪... – Matt 2010-10-20 13:45:17

+0

是... app/controllers/widgets_controller.rb存在並由腳手架腳本生成。謝謝你的檢查! – Coby 2010-10-20 21:35:29

回答

0

我確實做到了同樣的事情,它爲我工作。我做的唯一不同的是使用mysql數據庫。 爲什麼不刪除應用程序並重新執行。我無法想象你錯過了什麼。

這是我的步驟:

rails new TestApp -d mysql 
cd TestApp/ 
rails g scaffold widget name:text 
rake db:create 
rake db:migrate 
rake routes 
(in /home/gjp/work/TestApp) 
    widgets GET /widgets(.:format)   {:controller=>"widgets", :action=>"index"} 
    widgets POST /widgets(.:format)   {:controller=>"widgets", :action=>"create"} 
new_widget GET /widgets/new(.:format)  {:controller=>"widgets", :action=>"new"} 
edit_widget GET /widgets/:id/edit(.:format) {:controller=>"widgets", :action=>"edit"} 
    widget GET /widgets/:id(.:format)  {:controller=>"widgets", :action=>"show"} 
    widget PUT /widgets/:id(.:format)  {:controller=>"widgets", :action=>"update"} 
    widget DELETE /widgets/:id(.:format)  {:controller=>"widgets", :action=>"destroy"} 
rails s 

然後http://localhost:3000/widgets工作。

0

所以看起來我已經解決了這個問題(但我仍然不明白這一點!):

我所做的一切正在運行使用-d(分離模式),它直接返回你的服務器腳本回到控制檯。我試着在沒有-d選項的情況下運行服務器來查看服務器活動日誌所說的結果,當我以這種方式運行服務器腳本時,它直接崩潰,說端口已被使用(即使運行detatched它沒有' t crash?!?!?)。

重新啓動。一切正常,服務器腳本在任一模式下都能正常運行。

所以我想必須有一些背景端口綁定問題,重新啓動時擦乾淨。如果這種情況發生在將來的其他人身上,我猜想你可能會在某處綁定到你的主機端口,從而出現一些流氓流程(來自另一個rails應用的MAMP bug?流氓雜種服務器?)。檢查一下,如果你找不到任何重新啓動,看看它是否修復它。

聳肩

感謝您的輸入壽球員和/或加侖。

3

修改路由後需要重啓服務器。 正如你在答案中所說的那樣,你已經用-d選項啓動了服務器,所以它進入了後臺,然後你試圖再次運行它 - 但第一個仍在工作。你應該殺死第一臺服務器。

你提到的後臺進程並不是任何流氓進程,它是你的第一臺服務器。

答案是: 1)不要在開發中使用'-d'選項啓動服務器(所以稍後重啓或者更容易重啓) 2)更改路由後總是重啓服務器文件(或配置/初始化程序中的任何文件)

0

在正確運行的開發環境中,不必重新啓動服務器以重新加載路由。

忽略 - 因爲您在分離模式下啓動了第二臺服務器嘗試,所以未看到它收到的綁定錯誤。

在前臺運行服務器通常更容易,因此您可以看到任何錯誤。

如果你得到一個綁定錯誤,那麼你就可以追查:

sudo netstat -an | grep LISTEN | grep 3000 

ps aux | grep -i rails