1

我想在我的评论路线中添加一个 url,以便我可以调用“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
4

1 回答 1

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. Collection路由是链接到资源集合的路由
;不需要.id

有关详细信息,请参阅Rails 路由指南

于 2012-11-22T04:13:19.880 回答