【问题标题】:Rendering partials in rabl在 rabl 中渲染局部
【发布时间】:2011-12-12 11:13:27
【问题描述】:

我正在使用 RABL 来格式化 Rails API 的输出。我尝试了以下代码

message.rabl:

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

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

cmets.rabl:

object @comments
attributes :comment_body

我的问题是我的 message.rabl 没有呈现我的部分,即 cmets.rabl 。在 rabl.xml 中渲染局部的正确方法是什么?谢谢你。

【问题讨论】:

    标签: ruby-on-rails api partials rabl


    【解决方案1】:

    你很接近,这有点令人困惑,但在这些情况下使用 extends 而不是 partial:

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

    你应该很高兴。查看此https://github.com/nesquena/rabl/issues/58 以获得更详细的说明。

    【讨论】:

      猜你喜欢
      • 2012-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-16
      • 2016-11-12
      相关资源
      最近更新 更多