rabl
rabl copied to clipboard
Rabl not renders collection properly
Hi,
I'm struggling with some issue and not sure how to get out of it:
Here is my labels/index.rabl
collection @labels
attribute :id, :name
When I do next
renderer = Rabl::Renderer.new('labels/index', Label.limit(4), { :format => 'json', :view_path => 'app/views/api/pro/v2' }).render
=> "{\"name\":\"Label\"}"
which is totally wrong as it should display collection as an array of 4 hashes with proper id & name.
I'm not sure why it does like this.
So I'm using rails 4.2.11 & rabl 0.14.1
Wdyt?
Also, I found that when collection is empty, it doesn't return [] but {} so it makes api response different.
@nesquena @databyte Could you please check what's going on, as I spent 3hrs on it and didn't find any reason why this happenings.
Thanks a bunch in advance 🙏
If you could make a little rails app that reproduces just that, I can look into it later. It's hard to set everything up exactly the way you have it and hope I'm seeing what you're seeing.
I have the same problem after upgrading to the latest version of Rabl and using the same Rails version.
It occurs when trying to render a ActiveRecord::Collection. Calling .to_a on it before rendering fixes it.
Seems to be the same issue as described here:
https://github.com/nesquena/rabl/issues/724