我有comment资源。我有一个处理 的控制器,respond_with现在,它应该提供所有 JSON 响应(这是正确发生的)。我正在使用Rabl来处理我的 JSON/XML 渲染,并且我正在把事情弄干一点。我有正确的方式我希望comment在comments/show.rabl.
object @comment
attributes :id, :body, :a_few_more_things
当进行 POST 调用/comments/(触发create我的控制器上的方法)时,我希望 Rails 以与视图comment相同的格式返回show(上图)。我有,在我的create职能...
def create
# Skip some code, save it, ya-da ya-da
respond_with(@comment, :layout => 'comments/show')
end
这是行不通的;它只是返回一个comment带有所有属性的平面 JSON 实现。它没有使用我show.rabl的 at comments/show.rabl。如何让我的create操作返回 @commentshow.rabl用作布局?
我看到这篇文章指定了布局文件的完整路径和扩展名;我不应该那样做,不是吗?我用错了:symbol_option吗?应该是:location吗?