- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 rabl 中,我试图让一个 child 的元素是有条件的,但在条件评估为 false 的情况下,它仍然呈现没有属性的元素。
这是我的 .rabl:
child(:products) do
attribute :id, :if => lambda{ |p| p.store_id == @store.id }
end
希望 .json 看起来像这样:
"products":[{"id":2}]
但它也呈现空值:
"products":[{}, {"id":2}, {}]
有没有办法让空元素完全被忽略?
最佳答案
假设您期望在实例变量上使用 products
方法:
child(@catalogue.products.select{|p| p.store_id == @store.id} => :products ) do
attribute :id
end
关于ruby-on-rails - 删除 Rabl 中的空哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18212996/
我的 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
我是一名优秀的程序员,十分优秀!