I’ve got a comment resource. I’ve got a controller that handles respond_with, and for right now, it’s supposed to be serving up all JSON responses (which is happening correctly). I’m using Rabl to handle my JSON/XML rendering, and I’m DRY-ing things up a little. I have the proper way I want a comment to be rendered at comments/show.rabl.
object @comment
attributes :id, :body, :a_few_more_things
When a POST call is made on /comments/ (which fires the create method on my controller), I want Rails to return the comment in the same format as the show view (above). I’ve got, in my create function…
def create
# Skip some code, save it, ya-da ya-da
respond_with(@comment, :layout => 'comments/show')
end
This isn’t working; it’s just returning a flat JSON implementation of the comment with all of the attributes on it. It’s not using my show.rabl at comments/show.rabl. How do I get my create action to return the @comment using show.rabl as the layout?
I see this post specifies the full path and extension of the layout file; I shouldn’t have to do that, should I? Am I using the wrong :symbol_option? Should it be :location?
I was able to resolve this issue by creating a Rabl template at
comments/create.rabl.And that’s all she wrote. Rails looks for the
create.rablview, which accepts one objects and just renders the fields defined incomments/show.rabl.Thanks to Martin Harrigan for reminding me I still had my question open!