This project is archived and is in readonly mode.
[PATCH] respond_with with array of resources not working
Reported by Wojciech Wnętrzak | February 11th, 2011 @ 10:01 AM
There is a problem with respond_with arguments. Those examples
behaves completely different (second one is working
incorrect):
respond_with(:admin, @post)
respond_with([:admin, @post])
When there is passed array of resources, in this place, variable resources looks like
this: [[arg1, arg2]] which is wrong. After writing a patch, one
other test is falling, however I don't know what should be the
correct behaviour there.
So my question is: what should look like response from api request
(i.e. xml) of respond_with([:admin, @post]) - should there be only
@post included or maybe :admin also?
Now it returns both arguments, however code says that this should
be single resource (not resources), but now resource is mistakenly
taken as passed array.
I'm submiting patches with respond_with fix and test for it - after applying them, this test is falling.
Comments and changes to this ticket
-
Wojciech Wnętrzak February 11th, 2011 @ 10:20 AM
I forgot to add require 'active_support/core_ext/array/wrap' for patch with fix.
This patch should be used instead. -
José Valim February 11th, 2011 @ 01:12 PM
- State changed from new to invalid
- Assigned user set to José Valim
- Importance changed from to Low
Rails allows you to use respond_with([@admin, @post]) but Rails interprets it as a collection. The same as if you do: respond_with(Article.all).
That said, if you want to say you are redirecting to a nested resource, you have to do: respond_with(@admin, @post). Therefore, [[arg1, arg2]] is not wrong and the test that fails after your change is correct.
-
Wojciech Wnętrzak February 11th, 2011 @ 01:37 PM
One more question:
Let's say we have responder in create action like:respond_with([:admin, @post])
Also note about similarity of method respond_with to polymorphic_url is little misleading - there we can pass only array if we need nesting.
Documentation -
José Valim February 11th, 2011 @ 01:51 PM
Yes, it is intentional in the sense you should use respond_with(@admin, @post) instead. I agree with you about the note being misleading, I have just removed it. Thanks!
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>