This is a simple example of action specific javascript. It also allows you to pass data to JS from inside rails controllers. Works with Turbolinks 5 (not required).
Add the files below to your project, then insert <%= insert_javascript_hook %>
somewhere in the footer of your layout.
You'll need these gems:
gem 'jquery-rails'
gem 'jquery-turbolinks' # Only if you use Turbolinks
gem 'turbolinks', '~> 5.0.0' # Only if you use Turbolinks
# Somewhere in your JS stack
Javascript.controller 'Dashboard', index: ->
console.log this.params.test.some_value
# You can pass values to JS from Rails
class DashboardController < ApplicationController
def index
js test: { some_value: 'Hello from Rails!' }
end
end