0

I feel like I should know this and I'm certain this could be done more cleanly, but I'm not quite sure the best way to go about it.

How could a set of routes like this be written in a more DRY way?

# 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"
4

3 に答える 3

1

それはそれを行う必要があります:

resources :artists, path: '/' do
  member do
    get 'remixes'
    get 'originals'
    get 'popular'
    get 'mashups'
    get 'covers'
    get 'features'
  end
end
于 2012-10-07T17:47:32.633 に答える
1

1 つのルートを実行して、list_type をパラメーターとして渡します。

何かのようなもの

resources: artists do
  resources list_types
end

おそらく同様のことを行う一連のメソッドに対して個別のアクションを持たないようにします。

于 2012-10-07T17:17:48.093 に答える
0

ああ、これを熟考するべきだった(今日の二日酔い):

[:remixes_of, :remixes_by, :originals, :popular, :mashups, :covers, :productions, :features].each do |role|
  match ":id/#{role}", to: "artists\##{role}", as: "artist_#{role}"
end
于 2012-10-07T17:13:46.957 に答える