2012-10-07 62 views
0

我覺得我應該知道這一點,我確信這可以做得更乾淨,但我不太確定最好的方式去做。我怎樣才能更清楚地重寫這組路線?

這樣的一組路線怎麼可能以更乾的方式書寫?

# Artists 
match "/:id/remixes", :to => "artists#remixes", :as => "artist_remixes" 
match "/:id/originals", :to => "artists#originals", :as => "artist_originals" 
match "/:id/popular", :to => "artists#popular", :as => "artist_popular" 
match "/:id/mashups", :to => "artists#mashups", :as => "artist_mashups" 
match "/:id/covers", :to => "artists#covers", :as => "artist_covers" 
match "/:id/productions", :to => "artists#productions", :as => "artist_productions" 
match "/:id/features", :to => "artists#features", :as => "artist_features" 

回答

1

應該這樣做:

resources :artists, path: '/' do 
    member do 
    get 'remixes' 
    get 'originals' 
    get 'popular' 
    get 'mashups' 
    get 'covers' 
    get 'features' 
    end 
end 
+1

這就是它!路徑:'/'部分是我所需要的。 –

+0

只要給任何人閱讀便條,我的路徑被翻轉(這是有道理的)是​​'remixes_artist','originals_artist'等。 –

0

啊,應該通過(宿醉今天)剛剛想到這一點:

[:remixes_of, :remixes_by, :originals, :popular, :mashups, :covers, :productions, :features].each do |role| 
    match ":id/#{role}", to: "artists\##{role}", as: "artist_#{role}" 
end 
+0

雖然這是更緊湊,它不聲明或可讀。 – Agis

1

我想看看嘗試做1路,並通過LIST_TYPE作爲參數。

喜歡的東西

resources: artists do 
    resources list_types 
end 

我會盡量避免爲一堆,可能做類似的事情的方法單獨行動。

相關問題