Using RABL in Rails 3.2.x, given the following controller action:
respond_to :html, :json
def create
@foo = Foo.create(params[:foo])
respond_with @foo
end
Assuming the validation fails, how do you get respond_with to use a RABL template instead of the standard JSON hash of errors — IE. I would like other model attributes besides the validation error message sent back along with the request.
Suggestions?
I found this one out the hard way. You should create a custom responder for your application controller, or at least your individual response. See Three reasons to love ActionController::Responder for more details.
My solution:
You could also use
respond_with @foo, responder: ApiResponderinstead.Thanks to haxney for sending me in the right direction.