- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 RABL gem 为评论的用户呈现 JSON 用户数据,这些评论是注释的子级,注释的子级是图像的子级。我想做类似的事情:
object @image
node :annotations do
@image.annotations.map { |a| {
:id => a.id,
:x1 => a.x1,
:x2 => a.x2,
:y1 => a.y1,
:y2 => a.y2,
node :comments do
@image.annotations.comments.map { |c| {
:body => c.body,
:user_id => c.user_id,
:name => User.find(c.user_id).name,
:user_icon => user_icon(User.find(c.user_id), 'square', 30)
}}
end
}}
end
最佳答案
我从 @calvin-l 得到了这个答案.诀窍是只映射 a.comments 然后以这种方式从每个评论中获取数据:
node :annotations do
@image.annotations.map { |a| {
:id => a.id,
:x1 => a.x1,
:x2 => a.x2,
:y1 => a.y1,
:y2 => a.y2,
:comments => a.comments.map { |c| {
:body => c.body,
:created_at => c.created_at,
:user => {
:id => c.user.id,
:facebook_id => c.user.facebook_id,
:name => c.user.name,
:username => c.user.username
}
}}
}}
end
关于ruby-on-rails - Rails 3.1 与 RABL 的深度嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9428253/
我的 Rails 应用曾经生成如下所示的 JSON: {"paintings": [ {"id":1,"name":"a"}, {"id":2,"name":"b"} ] }
谁能帮我去掉“items”中的“item”元素 输出应该是: "list":{ "items":[ { { data1: "test"} , { data2: "test2"} } } collect
我必须按照 rabl 代码生成一些 JSON 数据。 object @event attributes :id, :EID, :name, :address, :description, :latit
为了提高速度,我正在从 jbuilder 迁移到 Rabl,以获取我网站上的搜索页面。在不进行任何其他优化的情况下,它似乎快了 50%,这很好。 不过,我在通过 rabl 向 View 发送回形针 U
我有这个 show.json.rabl 用于 Controller 的显示操作以在我的 Rails 应用程序中呈现一些 JSON,我认为 edit 操作的 JSON 响应与我的节目没有什么不同,所以我
我有一个 v1/queues/index.rabl 像: collection @queues extends "v1/queues/show" 但是我想要一个成功响应的模板,它可以嵌入队列信息,比如
如果我使用 node() 方法在 RABL 中创建子节点,我如何控制呈现的属性? JSON 输出是这样的: [ { "location": { "lat
我有一个包含父类和子类对象的提要,我使用 RABL 将其呈现为 json。我在 json 中包含根对象。 事情是这样的 => 根据先到的情况,json 中的根节点将生成相应的类。 我需要它是所有的父类
我正在尝试获取一个 json View ,该 View 使用 rabl 来让请求发送自定义属性,例如,如果模型有 :id, :first_name, :last_name 我只想调用我想要的值,比如只
我正在使用 RABL 输出 Sunspot/SOLR 结果集,搜索结果对象由多种模型类型组成。目前在 rabl View 中我有: object false child @search.results
我正在使用 RABL 来格式化 Rails API 的输出。我试过以下代码 消息.rabl: object @message attributes :id,:description,:created_
我正在为我的 API 使用 rabl 0.11.6,我发现自己对每个日期或时间对象一遍又一遍地执行以下操作: node :created_at do |article| article.creat
有谁知道如何在 rabl 文件中使用装饰器? collection @invitations child(:user) attributes .... 我希望能够做到这一点: collect
我有这个模板: # app/views/posts/index.rabl collection @posts => :posts attributes :id, :title, :subject ch
我正在尝试安装 spree gem,但我在安装 gem 时遇到了一些问题。目前我在尝试安装 rabl(0.13.1) gem 时遇到错误。我得到的许可被拒绝。想知道如何解决这个错误,以便我可以回去完成
当我使用 rabl 为标准 RESTful Controller 方法返回 JSON 时,我想我有一个非常基本的情况...... 首先,假设我与 parent 和 child 之间存在典型的一对多关系
我将 rabl 与 Rails 3.2 应用程序一起使用,我在 rabl View 文件中收到错误,但它没有指向发生错误的确切错误行。所以现在我想要调试查看该行导致错误的代码,例如 put 语句。 最
以下是我的拉 bool 观点: 学生/show.json.rabl object @student cache @student attribute :name, :gender, :age node
在 rabl 中,我试图让一个 child 的元素是有条件的,但在条件评估为 false 的情况下,它仍然呈现没有属性的元素。 这是我的 .rabl: child(:products) do at
我将一个简单的对象传递到我的 RABL View 中,rabl View 基本上是两行: object @invitations attributes :email, :active, :invita
我是一名优秀的程序员,十分优秀!