在控制器中:
def some_action
@foo = 'bar'
end
并在some_action.json.erb
:
<%= render :json => @foo %>
这会导致错误:
ArgumentError - You invoked render but did not give any of :partial, :template, :inline, :file or :text option.:
(gem) actionpack-3.2.10/lib/action_view/renderer/template_renderer.rb:36:in `ActionView::TemplateRenderer#determine_template'
(gem) actionpack-3.2.10/lib/action_view/renderer/template_renderer.rb:10:in `ActionView::TemplateRenderer#render'
(gem) actionpack-3.2.10/lib/action_view/renderer/renderer.rb:36:in `ActionView::Renderer#render_template'
(gem) actionpack-3.2.10/lib/action_view/renderer/renderer.rb:17:in `ActionView::Renderer#render'
(gem) actionpack-3.2.10/lib/action_view/helpers/rendering_helper.rb:24:in `#<Class:0xb4a2378>#render'
...
尽管我把头绕在它周围,但我不明白为什么render :json => ...
不应该在这里工作。我知道我可以直接从控制器为 format.json 渲染,但我试图通过视图来完成它,而不是在 .erb 中手动制作 json。
Ruby 1.9 上的 Rails 3.2.10