Skip to content

Instantly share code, notes, and snippets.

@raghubetina
Last active May 6, 2021 12:47
Show Gist options
  • Save raghubetina/2e9b56a89484b1ad503fc04b4a6bda75 to your computer and use it in GitHub Desktop.
Save raghubetina/2e9b56a89484b1ad503fc04b4a6bda75 to your computer and use it in GitHub Desktop.
Add Sprockets JS back to Rails 6 apps

Add Sprockets JS back to Rails 6 apps

  1. Create folder app/assets/javascripts

  2. Create file app/assets/javascripts/application.js

  3. Add some JS inside. You can use directives; e.g.:

    //= require_tree .
    
    console.log('howdy');
  4. In app/assets/config/manifest.js, add:

    //= link application.js
  5. In app/views/layouts/application.html.erb, add:

    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

That's it. If you used the example JS above, you should see "howdy" in the JS console when you visit a page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment