开发者

Active Resource in Rails 3.0, nested resource with non standard ID

I have a rails application that needs to refer to another rails application to populate some of it's models, and am using Active Resource to do it.

When I need to hit a route like:

/channels.xml

There is no problem at all, I can use the automatic mapping just fine...

But, I ALSO need to be able to handle a route lik开发者_Go百科e:

/channels/1/programs.xml

And this is where I'm stuck.

Just looking at the docs, it LOOKS like this might count as a custom restful route, in which case I would be stuck doing the horribly messy looking:

Channel.first.get(:programs)

Which not only looks terrible, ALSO does not work (the rails app that actually has the data sees

/channels//programs.xml

with no id in there. Which, you know, is cool since things get even MORE complicated and the "Channel" model in that other rails object is being built from a legacy database that doesn't have rails in mind (and hence no "id" column). Instead, it uses "station_id".

So, if I HAVE to use that messy Channel.get method, how can I make sure it sets the id correctly? CAN I do this from the ActiveResource app, or is there something I need to change in the source rails app?

Edit: Just in case someone suggests it, I HAVE tried Channel.first.get(:programs, :id => 1) but that just gets me a route like:

/channels//programs.xml?id=1.

Maybe I'll have to abandon restful routes and just pull the id from there....but I really don't want to...


look into something called prefix_options

self.prefix_options[:channel_id] = <some channel_id>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜