我使用的是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 "/"
所以我做了什麼錯?我怎麼解決這個問題?
看起來像你*不*刪除'public/index.html' :) – fl00r
您確定在刪除public/index.html後重新啓動服務器嗎? – Dogbert
HEH ???我不明白,但現在它工作。 我當然(100%)刪除public/index.html。我也重新啓動了服務器。我甚至清理了我的回收站......這畢竟無濟於事。唯一有幫助的是**從文件夾**中刪除圖像(public/images/rails.png)。之後,我得到了我的索引頁面。真的很奇怪......非常感謝! – Kirinriki