3

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

Adam Eberlin
  • 14,005
  • 5
  • 37
  • 49
Nik So
  • 16,683
  • 21
  • 74
  • 108

2 Answers2

1

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

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')
Castilho
  • 3,147
  • 16
  • 15