Closed czak closed 12 years ago
Hey thanks for your feedback, much appreciated. Here is some thoughts and answers.
code
blocks when I want access to the json hash for another object. I tend to use extends in most other cases as you showed there. I don't view it as too clumsy but if you have a better approach I am happy to consider it for the future.current_object
helper that achieves the effect but I probably won't be doing that personally anytime soon unless it becomes an essential use case for me. Thanks for the suggestion and I welcome a patch :)if
lambda. In fact I am pretty sure it does or did. I use child with if blocks in a couple of my APIs. Are you absolutely certain that they don't work? Notice the call to resolve_conditions
here: https://github.com/nesquena/rabl/blob/master/lib/rabl/builder.rb#L77. If this doesn't work it is a bug and I will fix that soon hopefully.Thanks again for your feedback and for trying RABL.
This post was very helpful. It was not immediately clear how to reuse templates from the README
.
child (:auto_judge, :if => lambda {|station| station._type == "HumanWorker"}) {....}
gives out <pre><code>(eval):7: syntax error, unexpected ',', expecting ')' child (:auto_judge, :if => lambda {|station| sta... ^
Is that a space after child? Might be the issue
child(:auto_judge, :if => lambda {|station| station._type == "HumanWorker"}) {....}
should work fine...what ruby are you using?
i'm using 1.9.2
child(:line,:if => lambda {@line!=nil}){... }
still no effect??? i'm really stuck on this, am i doing something wrong???
@xecutioner If it really doesn't work, hopefully I can fix it in the next release, I will have to play around. In the meantime try to use:
child @line => :line do
# ...
end unless @line.nil?
Closing this but adding a link the wiki, the bugs mentioned here should be fixed.
Seems bug is back child (@products, :if => lambda {|product| product.active?}) do
eval):4: syntax error, unexpected ',', expecting ')' child (@products, :if => lambda {|product| product.active?}) do
It might be the space before the paranthesis, can you try:
child @products, :if => lambda {|product| product.active?} do
# ...
end
Don't know if there's a Google Group or anything, so I'm just posting here. I've been working on a REST API for a Rails app for the past 2 months and just discovered
rabl
. It might be something I've been looking for. Converted a few resources fromas_json
to.json.rabl
and it seems cool so far.I've got a few questions/ideas.
1. What's the proper way to extend a
@object
template from a@collection
template?I've got a
posts
resource and want to re-use theshow
template in theindex
template vibratim. Here's what I've come up with:posts/show.json.rabl
:posts/index.json.rabl
:It seems clumsy, but it works. I was kind of expecting a
partial
somewhere here. What would be the proper way to do that?2. Using regular
if
s within a templateInstead of the
:if => lambda { ... }
pattern, I tried using regularif
s within a template:posts/show.json.rabl
This works also, but presents a problem when using
extends
as presented above. The controller for anindex
action only provides the@posts
collection, so the@post
is nil and theif
always fails when rendering theindex
action. I think it would be cleaner to use regularif
s. Especially when adding multiple custom fields - this would just be a singleif
block instead of multiplecode(:field, :if => lambda { ... repeating condition ... })
blocks.Maybe the way to do it could be - instead of relying on instance variables, provide an
object
orcollection
helper, which can always access the current object? Kind of like RSpec utilisessubject
.3. Conditional
child
elementsI needed to include an entire subresource based on a condition. This didn't work:
So I eventually went with:
This works, but breaks
DRY
. I have ausers/show.json.rabl
with properly defined attributes, and would like to re-use it here. How would I go about it?All in all, thanks for the great work. These are just some of my thoughts, Markdown-formatted. I'd be glad to dig into the code if you see any point in my mumbling ;) Cheers!