Rails STI 路由 [英] Rails STI routing

查看:50
本文介绍了Rails STI 路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 STI 的文章模型.子类是情感、类别、网关等...

I've got an article model which uses STI. The sub classes are emotions, categories, gateways etc...

在我的路线中,我有

resources :emotions, :controller => 'articles'
resources :categories, :controller => 'articles'
resources :gateways, :controller => 'articles'

这使得所有不同的子类都可以在/articles/108 或emotions/108 或categories/108 中使用 - 无论您将哪个子类放在最前面,它们都适用于所有文章.

This makes all the different sub classes available at /articles/108 or emotions/108 or categories/108 - it doesn't matter which subclass you stick at the front they all work for all articles.

我希望我所有的 url 助手都能生成文章/id 的链接 - 目前它们仍然转到特定的子类.

I would like all my url helpers to produce links to articles/id - at the moment they still go to the particular sub class.

我该怎么做?

推荐答案

如果 article 是另一个派生类的基类,比如 gateway (class Gateway ),那么也许只使用 urls由 resources :articles 生成.应该可以使用文章助手 article_path(gateway),因为子类是从基类派生的.

If article is the base class of another derived class like gateway (class Gateway < Article), then maybe just use the urls generated by resources :articles. It should be possible to use the articles helper article_path(gateway) since the subclasses are derived from the base class.

这篇关于Rails STI 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆