【发布时间】:2015-01-21 09:38:09
【问题描述】:
http://guides.rubyonrails.org/layouts_and_rendering.html#using-render 2.2.9 渲染 JSON 说可以在视图中渲染 JSON 如下:
render json: @product
我无法让它工作。在 index.html.erb 我有:
render json: @trees
(@trees 被定义为 Tree.all,其中包含一个 Ancestry 树,FWIW - 据我所知,与问题无关。)
我在该行收到以下错误:
你调用了 render 但没有给出任何 :partial、:template、 :inline、:file、:plain、:text 或 :body 选项。
如果我将该行代码更改为:
render json: {text:"hello world"}
我做错了什么?
【问题讨论】:
标签: ruby-on-rails json ruby-on-rails-4 ancestry