her
her copied to clipboard
Proposed solution to issue #224, getting the expected request_path when ...
...creating a nested resource
This solution follows along the lines of what you do with the parent id and includes the parent request path when building the resource.
Please give some feedback on this, if it's a fair solution, if something is missing. I would like your thought on this.
Hi there, is this going to be merged at some point? If not it would be a good idea to fix the readme
same here wondering what's the status, seems a missing feature or common gotcha. will use this fork for a while and see if there's any side effects. meanwhile @remiprev could you please take a look and give some feedbacks when you have time?
seems to do the job :+1:
adding this thread to watchlist and waiting for merge & new release :)
It seems to me that this path would only get used once (i.e. for the #create
or first #save
, but then be deleted and not used in subsequent requests).
Example (not tested):
comment = @user.comments.create( body: "Your really bad at grammar" ) # POST /users/:user_id/comments
comment.body = "You're really bad at grammar".
comment.save # PUT /comments/:comment_id
Is that the desired behavior? I know for our APIs we would make subsequent PUTS to /users/:user_id/comments/:comment_id
.
Perhaps this should be set as a instance variable (instead of a temporary attribute) on the model, so that it can be used repeatedly.
I'm not sure that this is such a good idea. Having an association doesn't necessarily mean that the parent path should be prepended like this. It really depends on the API. You can work around it by explicitly defining the collection_path but you may have noticed that this doesn't work for nested associations. I have fixed this in #318.
On the other hand, if you need to access a model directly as well as through an association then setting collection_path won't help. This is a tricky one. Maybe we need to be able to explicitly state the path that is used for direct access, if there is one, as well as the path used for each association. These paths could all be the same in some cases or they could all differ.
@edtjones, if you're looking at this one, I'd really appreciate having a chat with you about it.