Remove script from layouts/application and placed the code in javascript/application.js.