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

Trying to render an OpenStruct object #437

Open
phlegx opened this issue Apr 9, 2013 · 1 comment
Open

Trying to render an OpenStruct object #437

phlegx opened this issue Apr 9, 2013 · 1 comment

Comments

@phlegx
Copy link

phlegx commented Apr 9, 2013

Hi folks!

I'm new to Rabl and I'm trying to render an OpenStruct object like this (and I'm really not sure If I do this correctly):

collection @all_authentications 
@all_authentications.marshal_dump.each do  |k,v| 
  v.each do |attr|
    node(k.to_sym) {attributes :id => attr.id, :token => attr.token }
  end  
end

But this gives me the following error as soon I restart the server and try to load my "authentication" view (haml and json both are throwing this). I have to modify the rabl fike AND to restart the server then, because simply modifying the rabl file does not solve the issue

undefined method `marshal_dump' for nil:NilClass

When I comment the Rabl code out and then restart the server and load my "authenication" view, haml and json do work fine again adn the correct json is delivered.
On the running server I then include the above code again and reload the "authenication" view again, then all is working fine.

So it seems that after a restart the object is nil... I have no clue what is wrong.

thank you in advance
p.

@phlegx
Copy link
Author

phlegx commented Apr 26, 2013

I just wanted to state that this problem happens because of the apipie gem. When I disable apipie commands, I do not get a blank page anymore.

However executing the code without apipie:

collection @all_authentications 
@all_authentications.marshal_dump.each do  |k,v| 
  v.each do |attr|
    node(k.to_sym) {attributes :id => attr.id, :token => attr.token }
  end  
end

now gives me the follwing error:

undefined method `first' for nil:NilClass

Means that I still don't know how to render an openstruct object correctly with rabl and I'm very open for any advise.


UPDATE: when I use object instead of collection then it works. Now I need to find a way to define the node within the first loop not within the second one.

UPDATE2: Looks like that did the trick:

object @all_authentications 
@all_authentications.marshal_dump.each do  |k,v| 
    node(k.to_sym) {
    v.each do |attr|
        attributes :id => attr.id, :token => attr.token 
    end
    }
end

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

1 participant