ruby-on-rails - 在 rabl 中渲染部分

标签 ruby-on-rails api partials rabl

我正在使用 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/

相关文章:

ruby-on-rails - 更改索引页 - Ruby on Rails

mysql - rails : can't get the attributes from the joined table

java - 分配了null的Object数据类型的响应-Java

python - 猎鹰python中的数据传递应用程序

c# - 如何使用用户选择的背景颜色覆盖图标的默认背景?

ruby-on-rails - 尝试使用 mongoid 作为 orm in rails 连接到 ec2 上的 mongodb 实例

ruby-on-rails - VCR:创建第二个磁带时为 "There is currently no cassette in use."

javascript - 如何使用 OAuth2 从 linkedin 获取最近的公司更新

php - 将对象传递给ZF2中的partial() View 助手

ruby-on-rails - 在 Ruby on Rails 部分中渲染 React 组件