3
votes

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

2
Can you try to add render :show in your def edit for your controller? - Jesse Wolgamott

2 Answers

1
votes

If you are using rabl >= '0.11.6', you would have to provide the view_path parameter (that is if it is not already set globally in your rabl.rb config file) like so:

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

else you would get the following error:

RuntimeError (Cannot find rabl template 'users/show' within registered ([]) view paths!):
0
votes

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')