Rails Nested Resource Issues
Dmitri Dolguikh
dmitri at redhat.com
Fri Sep 21 10:16:05 UTC 2012
On 20/09/12 01:20 PM, Martyn Taylor wrote:
> Gents.
>
> I'm having some trouble with getting nested resources working properly
> from bespoke XML/JSON in RESTful API. There seems to be some
> fundamental problems with the way rails works, which means we have to
> write a lot of bespoke code to get it working, possibly even having to
> monkey patch Rails itself.
>
> I've written an example rails app that highlights the problem and put
> a detailed description in the README you can find it here:
>
> https://github.com/mtaylor/Rails-Nested-Resource-Issues
>
> I've ran into this issue on IME. But it's going to affect us across
> all rails projects with REST APIs, so we could do with discussing this
> issue and coming up with the best possible solution that results in as
> little replication as possible.
>
> Please read through the problem and let me know if you have any better
> ideas that the solutions I have proposed.
>
> Regards
>
> Martyn
I think the reason for the somewhat odd approach chosen for
'accepts_nested_attributes_for' is, at least in part, due to
complexities involved in turning of the attribute setter into a factory
method. Not only this is messy, but also introduces side-effects, and
genuine 'WTH' moments.
The solution that we have works quite well for web-ui's, but not so much
for API's.
Having said that, I'll side with Jir(í that the least invasive/offensive
solution is to do necessary transformations in the controller. I think I
like the idea of not creating nested resources at all through API,
especially if they are first-class ones (as opposed to embedded-only ones).
-d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.fedorahosted.org/pipermail/aeolus-devel/attachments/20120921/4db803d3/attachment.html>
More information about the aeolus-devel
mailing list