-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion for dsl #3
Comments
Of course! Is it backwards compatible? On Fri, Jul 29, 2011 at 11:25 AM, jeroenvandijk <
|
Interesting, glad I read this first. I had an issue, perhaps I was using the normal syntax improperly. parent_model_name {
id parent_model.id
name parent_model.name
@child_models.each do |child|
child_model_name {
id child.id
attr1 child.attr1
}
end
} was producing JSON like this: { "child_model_name":
[
{
"id": 1,
"attr1": "some attr 1",
},
{
"id": 2,
"attr1": "another attr 1",
}
]
} Which was as expected. But if there was only one "child model" I would receive this (JSON) { "child_model_name":
{
"id": 1,
"attr1": "some attr 1",
}
} Not as a JSON array. I was expecting it to return me an Array regardless if it only had one element. This of course works fine in XML. Switching my hypertemplate syntax to: id parent_model.id
name parent_model.name
members(:collection => @child_models, :root => 'child_model_name') do |child|
id child.id
attr1 child.attr1
end Seemed to address the issue, properly wrapping the single child in an array. |
I excluded the parent model wrapper stuff in my late code samples. |
I think this is my misunderstanding, what I needed could be accomplished regardless of the hack, I believe. I just needed to use the members call regardless, though I was under the impression that 'members' is a deprecated method. If that is true, then how would you get this behavior? AR:Collection? |
I've created this hack for hypertemplate: https://gist.github.com/1113898
It allows for having something like the following:
This will return something like the following
Would je be willing to add something like this?
The text was updated successfully, but these errors were encountered: