## I used Coffee Script syntax ## @ sign here to set this function available in .erb file @yourFunction = (auth_token) -> $.ajax({ type: "GET", url: "/url/path", headers: { 'Authorization': 'Token token=' + auth_token } }).done((data) -> console.log(data) ).fail((jqXHR, textStatus, errorThrown) -> console.log("Request failed: " + textStatus) console.log(errorThrown) });