rabl icon indicating copy to clipboard operation
rabl copied to clipboard

Rabl not renders collection properly

Open zauzaj opened this issue 6 years ago • 4 comments
trafficstars

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?

zauzaj avatar Jun 27 '19 11:06 zauzaj

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 🙏

zauzaj avatar Jun 27 '19 16:06 zauzaj

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.

databyte avatar Jun 27 '19 17:06 databyte

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.

ddefrenne avatar Aug 07 '19 11:08 ddefrenne

Seems to be the same issue as described here:

https://github.com/nesquena/rabl/issues/724

swiknaba avatar Oct 05 '19 20:10 swiknaba