2012-11-22 81 views
1

我想添加一個網址到我的評論路由,所以我可以調用「post_comments_latest_path」。我添加了'get「comments/latest」=>「comments#latest」,:as =>「latest」',但是路由添加了:commend_id,而不需要該路徑。有什麼建議麼?將新路線添加到沒有添加參數的資源?

resources :posts, :except => [:index] do 
    resources :comments, :except => [:index, :show] do 
     post "replies" => "comments#create_reply", :as => "create_reply" 
     get "replies/new" => "comments#new_reply", :as => "new_reply"   
    end 
    end 

回答

0

這應該工作:

resources :posts, :except => [:index] do 
    resources :comments, :except => [:index, :show] do 
    post "replies" => "comments#create_reply", :as => "create_rely" 
    get "replies/new" => "comments#new_reply", :as => "new_reply" 
    get "latest", :on => "collection" 
    end 
end 

一個會員路線是一個鏈接到一個特定的資源;需要id
A 集合路由是一種鏈接到資源收集;不需要id

查看Rails Routing Guide瞭解更多信息。

+0

謝謝你的回答。我對這個系列有點困惑。 – user1461119