Search code examples
ruby-on-railsrabl

rabl reusing a template


I have this show.json.rabl for the show action of a controller to render out some JSON in my Rails app, I figure that the edit action's JSON response is no different than my show one, so I wonder if there is a method to use the show.json.rabl for the edit action.

I know that I can use "extend users/show in my edit.json.rabl, but what if I want to get rid of edit.json.rabl altogether and have a line in the controller that specifies that this action's json response should use show action's rabl template. Can this be done?

Thank you


Solution

  • I don't know if there is a better way, but you can render the JSON directly with Rabl

    render :inline => Rabl::Renderer.json(@user, 'users/show')