2010-11-26 51 views
0

在軌道2版我的應用我有這個資源定義Rails 3中的問題與自定義命名從軌更新後足智多謀路線2

map.resources :albums, :as => 'music', :has_many => :reviews 

這給了我一些標準線路:

album GET /music/:id(.:format) {:controller=>"albums", :action=>"show"} 
new_album GET /music/new(.:format) {:controller=>"albums", :action=>"new"} 

我也有一個多態關聯設置如下:

class Album < ActiveRecord::Base 
    has_many :reviews, :as => :reviewable 
end 


class Review < ActiveRecord::Base 
    belongs_to :reviewable, :polymorphic => true 
end 

這意味着我可以創建一個lin通過使用多態路徑

<%= review.reviewable.title, polymorphic_path(review.reviewable) %> 

但是k到我的專輯資源通過我的檢討,因爲升級到Rails 3中,我改變了我的路線文件,以便符合新的路由器:

resources :music, :controller => 'albums' do 
    resources :reviews 
end 

雖然清潔它打破了我的多態鏈接,即

<%= review.reviewable.title, polymorphic_path(review.reviewable) %> 

我結束了以下錯誤消息

undefined method `album_path' 

如果我看在我的軌道3個生成的路由與「回扣路線」我看到

music GET /music/:id(.:format) {:action=>"show", :controller=>"albums"} 

這是不同的東西在那裏之前在軌道2,即

album GET /music/:id(.:format) {:controller=>"albums", :action=>"show"} 

所以我的猜測是,這是破壞事物。

我有點不確定,但如何解決它,而不會恢復到軌道2將與軌道3.1折舊的路線。任何幫助,將不勝感激。謝謝。

回答

2

事實證明,這很容易解決。我所要做的只是:

resources :albums, :path => 'music' do 
    resources :reviews 
end