suggests to use "respond_to":
http://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to