2013-04-23 159 views
0

在我的Rails應用程序中,我使用了豐富的路由來實現基本的CRUD功能。但在某些情況下,我會向控制器添加新的視圖和方法(例如,特定的報告功能)。這些會自動包含在豐富的路線中嗎?或者我是否必須爲每一個routes.rb中的獲取或匹配行?Rails資源路徑

這裏是我如何與現在的routes.rb去...這似乎只是如果我有明確指定的一切,這是會得到unweildy隨着應用的增長...

resources :procedures 

    resources :headlines 

    devise_for :users 

    resources :services 

    resources :headlines 

    get "welcome/index" 
    get "welcome/profile" 
    get "welcome/kpi" 
    get "welcome/inventory" 
    get "public/index" 
    match "insurancelist" => "appointments#insurancelist" 


    get "admin/index" 
    get "dentrix/index" 
    get "dexis/index" 
    get "eaglesoft/index" 
    get "reports/index" 
    get "reports/dentist" 
    get "reports/office" 
    get "reports/collections" 


    resources :patients 

shallow do 
    resources :locations do 
    resources :practitioners do 
     resources :timecards 
     resources :appointments 
    end 
    end 
end 
+0

不,他們不會「自動添加」。你可以[添加足智多謀的路線](http://guides.rubyonrails.org/routing.html#adding-more-restful-actions)。 – 2013-04-23 19:09:09

回答

1

你應該閱讀官方Rails指南中的路線here

這裏有一些針對你的問題的快速提示(因爲我看到你想爲你的資源添加一些非REST動作)。

讓我們來看看。例如,您有一個項目模型和projects資源。並且您希望爲項目項目添加print操作(例如,在此操作中您將準備要在紙張上打印的報告)和published整個項目資源的操作(僅作爲某種報告的選擇操作):

你應當寫信給你routes.rb下一行:

resources :projects do 
    collection do 
    get :published 
    end 

    member do 
    get :print 
    end 
end 

該代碼給你未來的路線:

GET /projects   => projects#index 
GET /projects/published => projects#published 
GET /projects/new  => projects#new 
POST /projects   => projects#create 
DELETE /projects/:id  => projects#destroy 
PUT /projects/:id  => projects#update 
GET /projects/:id  => projects#show 
GET /projects/:id/edit => projects#edit 
GET /projects/:id/print => projects#print 
1

這些額外的路線沒有得到列入足智多謀路線。對於你的例子中的路線,不幸的是,真的沒有辦法壓縮它們,並且它們每個都需要在路線文件中有一個單獨的行。