如何在 AMS 上的括号内呈现 json 一些没有括号的变量
How to render json some variables without brackets inside brackets on AMS
我想知道是否可以使用 AMS 在带括号的渲染中渲染不带参数的变量?
例如:
render json: { comments: @comments, status: 200, hasMore: hasMore }
我想只呈现没有评论的@comments: 并且 hasMore: hasMore 显示在 json 上,这在括号内是可能的!
这样
render json: @comments, hasMore: hasMore, include: ['user', 'replies.**']
没有在 json
上显示 hasMore
如果您正在渲染 json,您需要确保作为 json 传递的内容实际上是有效的 json。这是一个最简单的例子:
# this does not work and will throw a syntax error
render json: 'foo: 'foo', bar: 'bar'
但是
# this works
render json: {foo: 'foo', bar: 'bar'}
# this works because it will render an array type
render json: @comments # assuming that is a collection
我想知道是否可以使用 AMS 在带括号的渲染中渲染不带参数的变量?
例如:
render json: { comments: @comments, status: 200, hasMore: hasMore }
我想只呈现没有评论的@comments: 并且 hasMore: hasMore 显示在 json 上,这在括号内是可能的!
这样
render json: @comments, hasMore: hasMore, include: ['user', 'replies.**']
没有在 json
上显示 hasMore如果您正在渲染 json,您需要确保作为 json 传递的内容实际上是有效的 json。这是一个最简单的例子:
# this does not work and will throw a syntax error
render json: 'foo: 'foo', bar: 'bar'
但是
# this works
render json: {foo: 'foo', bar: 'bar'}
# this works because it will render an array type
render json: @comments # assuming that is a collection