Rails STI 协会和嵌套资源
好吧,我这里有一个奇怪的模式,我无法弄清楚。
我有一个 STI 集,以 CallList 作为基本模型,以 City & 模型为基础。国家继承。一个城市属于一个州(一个州有许多城市)。
一个营销活动有很多通话列表,因此我想将它们全部显示出来。我循环遍历campaign.call_lists,有时会得到城市,有时会得到州。当我想链接到它们时,
link_to call_list.name, call_list
如果我有这些路线,那么效果很好:
resources :cities, :states
但是,当我将城市嵌套在州内时,link_to 帮助程序无法找出适当的路线。有没有一种简单的方法可以做到这一点,或者我是否必须进行一些手动路径助手构建?
Ok, so I've got a weird pattern here that I can't figure out.
I have an STI set with CallList as the base model, and City & State inherited. A city belongs to a state (and a state has many cities).
A campaign has many call lists, so I want to display them all. I loop over campaign.call_lists and sometimes get Cities, sometimes States. When I want to link to them I do
link_to call_list.name, call_list
which works fine if I have these routes:
resources :cities, :states
When I nest cities inside states, however, the link_to helper can't figure out the appropriate route. Is there a simple way to do this, or am I going to have to do some manual path helper construction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要检查 call_list 的类型,然后使用正确的路由。它不能直接使用,因为路由是嵌套的。
you need to check for kind of call_list and then use proper route..it can not be directly as route is nested..