我正在使用 RABL 来格式化 Rails API 的输出。我试过以下代码
消息.rabl:
object @message
attributes :id,:description,:created_at,:created_by_user_id
child @comments do |t|
partial("user/comment", :object => @comments)
end
评论.rbl:
object @comments
attributes :comment_body
我的问题是我的 message.rabl 没有呈现我的部分,即 comments.rabl 。在 rabl 中渲染部分的正确方法是什么?谢谢你。
最佳答案
你很接近,这有点令人困惑,但在这些情况下使用扩展而不是部分:
child @comments do |t|
extends "user/comment"
end
你应该很高兴去。检查这个 https://github.com/nesquena/rabl/issues/58以获得更详细的解释。
关于ruby-on-rails - 在 rabl 中渲染部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7847843/