2016-08-02 88 views
0

我在軌的模型,我稱它爲free_mess更改型號名稱軌

我的路線文件包含resources :free_mess

顯然,這型號是不理想的在瀏覽器中顯示,它顯示了像這樣:

localhost:3000/free_mess/show 
localhost:3000/free_mess/index 
localhost:3000/free_mess/message1 

我需要在瀏覽器中free_mess更改爲更具可讀性像'messages'。所以,瀏覽器顯示此:

localhost:3000/messages/show 
localhost:3000/messages/index 
localhost:3000/messages/message1 

回答

3
resources :free_mess, path: 'messages' 

這將在應用程式中加入別名路線。

但是,如果你要重命名的路徑的shhelper方法,那麼你應該做的:

resources :stories, :path => :books, :as => :books 

參見:Overriding the Named Helpers

-1

您可以指定一個路徑選擇:

resources :free_mess, path: 'messages' 
0

在配置做到這一點/ routes.rb中

得到這個

localhost:3000/messages/show 
localhost:3000/messages/index 
localhost:3000/messages/message1 

做這個

get 'messages/show' => 'free_mess#show' 
get 'messages/index' => 'free_mess#index' 
get 'messages/message1' => 'free_mess#message1'