Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering partials in rabl

I am using RABL to format the output of a Rails API. I tried following code

message.rabl:

object @message
attributes :id,:description,:created_at,:created_by_user_id

child @comments do |t|
     partial("user/comment", :object => @comments)
end

comments.rabl:

object @comments
attributes :comment_body

My problem is that my message.rabl not rendering my partial i.e. comments.rabl . What is the proper way to render partials in rabl. Thank you.

like image 498
nilkash Avatar asked Dec 28 '22 12:12

nilkash


1 Answers

You were close, and it is a bit confusing but use extends instead of partial for these cases:

child @comments do |t|
  extends "user/comment"
end

and you should be good to go. Check this https://github.com/nesquena/rabl/issues/58 for a more detailed explanation.

like image 170
Nathan Avatar answered Dec 30 '22 07:12

Nathan