开发者

Rails STI Association and nested resources

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.nam开发者_运维知识库e, 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?


you need to check for kind of call_list and then use proper route..it can not be directly as route is nested..

link_to call_list.name, call_list.is_a?(City) ? call_list : state_city_path(call_list)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜