Skip to content
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

Rabl not renders collection properly #726

Open
zauzaj opened this issue Jun 27, 2019 · 4 comments
Open

Rabl not renders collection properly #726

zauzaj opened this issue Jun 27, 2019 · 4 comments

Comments

@zauzaj
Copy link

zauzaj commented Jun 27, 2019

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
Copy link
Author

zauzaj commented Jun 27, 2019

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 🙏

@databyte
Copy link
Collaborator

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.

@ddefrenne
Copy link

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.

@swiknaba
Copy link

swiknaba commented Oct 5, 2019

Seems to be the same issue as described here:

#724

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants