我有一个comment
资源。我有一个处理respond_with
的控制器,现在它应该可以提供所有JSON响应(正确发生)。我使用Rabl来处理我的JSON/XML渲染,而且我正在干一些事情。我有正确的方式我想要一个comment
呈现在comments/show.rabl
。Rails 3 respond_with:在资源创建时显示“show”布局
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
在comments/show.rabl
。 如何使用show.rabl
作为布局返回@comment的动作create
?
我看到this post指定布局文件的完整路径和扩展名;我不应该这样做,我应该吗?我使用错了:symbol_option
?应该是:location
?
采取在[JBuilder的顶(https://github.com/rails/ JBuilder中) – Damien