2011-08-10 41 views
1

我使用的是Rails 3,並且感覺到索引(http:// localhost:3000)的路由更改語法與以前的版本不同。Rails 3 - 改變索引

我想打開employees-controller(現在可以用localhost:3000/employees打開)的默認頁面(localhost:3000)的動態索引頁面(index.html.erb)。我認爲這是很容易的,因爲在其路由的書面:

# You can have the root of your site routed with "root" 
    # just remember to delete public/index.html. 
    # root :to => "welcome#index" 

所以這就是我確實是:我刪除public/index.html並設置root :to => "employees#index"。 但是當我打開服務器並打開localhost:3000時,它仍然打開「歡迎國外!」-page。很奇怪!

所以我用Google搜索這個問題,發現答案,上面寫着:我應該寫這在我的路線文件: - 「歡迎海外」

map.root :controller => 'employees', :action => 'index'

同樣在這裏我也仍然獲得 - 網頁和rails-shell說「未定義的局部變量或方法'map'」。 (我認爲這是舊的語法爲Rails 2 ...?)

match "/" => "employees#index"routing error: No route matches "/"

所以我做了什麼錯?我怎麼解決這個問題?

+0

看起來像你*不*刪除'public/index.html' :) – fl00r

+0

您確定在刪除public/index.html後重新啓動服務器嗎? – Dogbert

+0

HEH ???我不明白,但現在它工作。 我當然(100%)刪除public/index.html。我也重新啓動了服務器。我甚至清理了我的回收站......這畢竟無濟於事。唯一有幫助的是**從文件夾**中刪除圖像(public/images/rails.png)。之後,我得到了我的索引頁面。真的很奇怪......非常感謝! – Kirinriki

回答

0

爲什麼在Rails 3中使用「map」?應該是:

root :to => "employees#index" 
+1

是的,我意識到這不是正確的Rails 3的方法。我是Rails的新手,所以我不習慣這些約定,並用google搜索答案,只是困惑了我:) – Kirinriki

+0

沒問題,歡呼:) – socjopata

0

我認爲問題在於cookies。請清除Cookie並刷新頁面。

+0

我認爲這是問題所在。哦,我愚蠢。謝謝! – Kirinriki