I'm attempting to run javascript on specific pages and my only solution seems like an anti-pattern. I have controller.js
generated inside of assets/javascripts/
. I'm using gem 'jquery-turbolinks'
I have code resembling the following:
$(document).ready(function () {
//Initiate DataTables ect..
}
)
This code is firing on every page So I added the following inside of it.
if ($('#page-specific_element').length > 0) {
//Initiate Datatables ect.
}
My question being, is there a way to set rails to utilize only the javascript files necessary to a specific controller or is logic gating behind an element search the best solution?