Abhi Abhi - 6 months ago 24
Ruby Question

How to pass object into rabl partial?

I need to create a rabl partial, where I need access to an object. For Eg:-

# app/views/posts/index.rabl
collection @posts

node(false) { |post| partial('posts/show', :object => :post)}


Inside show.rabl

# app/views/posts/index.rabl
object @post

node(:details) do
{:id => @post.id}
end


Gives me, undefined method id for nil class. What am I doing wrong? Even the documentation gives the same steps.

RSB RSB
Answer

Have you tried this?

locals[:object].id

Hope this helps!