我有一個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