-
Notifications
You must be signed in to change notification settings - Fork 335
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
How to set node root on mapped partial renders #466
Comments
How about this: node :subviews do |obj|
obj.subviews.map do |subview|
{ subview.key => partial('kb_view/base', object: subview) }
end
end ? |
Ah! Thanks for the quick response. This is extremely close - instead of an array of dictionaries though:
How would I create a dictionary of dictionaries? Is this even possible?
Sorry for the multiple somewhat lame questions - theres an extremely specific output structure i've been struggling creating using RABL and I don't have much flexibility in doing it differently. |
Definitely possible with each_with_object: node :subviews do |obj|
obj.subviews.each_with_object do |subview, result|
result[subview.key] = partial('kb_view/base', object: subview)
end
end See how close that gets you. I don't mind the questions, I readily admit rabl works much better with "standard-ish" responses and it can get a little tricky with these super custom ones. But almost anything is do-able. |
Ah that makes sense! Currently, your snippet is causing a "wrong number of arguments" error on my base RABL class. Might be due to some incorrect extending of RABL templates. Looking into it - I'll let you know if this works. Thanks again. |
Ok I think that should get you pretty close. Let me know if you get it working. On Tue, Jun 18, 2013 at 12:25 PM, Praveen Sharma [email protected]
|
Thanks for all your help Nesquena - the final solution was:
The only issue was missing the ({}) at the end of each_with_object |
Ah yeah right, I aircoded it glad you found that missing piece |
Hi everyone! I have a questions about structuring my RABL JSON output.
I have the following snippet of RABL:
This outputs the following JSON:
I need to change this to the following output, using the "subview.key" property:
Any ideas? In my partial i have: object :subview => :subview.key, :root => :subview.key
Which I thought should set the root of the partial to be the subview.key property.
The text was updated successfully, but these errors were encountered: