【发布时间】:2014-02-14 12:41:09
【问题描述】:
我一直在想办法让 RABL 渲染一个非常简单的 JSON 字符串数组,例如:["my,"array","of","strings"]
控制器是
class StringsController < ApplicationController
responds_to :json
def index
@string = ['my','array','of','strings']
respond_with @strings
end
end
RABL 视图必须从以下内容开始:
collection @strings, root_object: false
但我不知道如何只输出没有节点名称或对象内的字符串...
显然有一个更直接的解决方案来实际提供 JSON 数组,就像我在下面所说的那样,但我特别感兴趣的是为什么这在 RABL 中看起来如此复杂!
class StringsController < ApplicationController
def index
render json: ['my','array','of','strings']
end
end
【问题讨论】:
-
在 rabl 中,集合将采用 json 对象而不是数组。
标签: ruby-on-rails json rabl