Use respond_with and respond_to.