Rails路由:灵活的资源路径取决于属性
Rails Routing: Flexible Resource Path depending on attributes
如何根据资源的属性使资源路由足够灵活?
例如,
resources :articles, param: :article_slug do
member do
resources :comments
end
end
Article
具有 title, category, slug, etc
的属性
但是客户希望类别必须是第一个出现在url中,例如:/entertainment/articles/:article_slug/comments/:id
或/sports/articles/:article_slug/comments/:id
。我不知道什么是正确的方法。
尝试
scope path: ':category' do
resources :articles, param: :article_slug do
resources :comments
end
end
end
并以这种方式生成url,
article_comment_path(@article, @comment, category: @article.category)
如何根据资源的属性使资源路由足够灵活?
例如,
resources :articles, param: :article_slug do
member do
resources :comments
end
end
Article
具有 title, category, slug, etc
但是客户希望类别必须是第一个出现在url中,例如:/entertainment/articles/:article_slug/comments/:id
或/sports/articles/:article_slug/comments/:id
。我不知道什么是正确的方法。
尝试
scope path: ':category' do
resources :articles, param: :article_slug do
resources :comments
end
end
end
并以这种方式生成url,
article_comment_path(@article, @comment, category: @article.category)