我一直在尝试找出如何让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