Kiran Patil
Kiran Patil

Reputation: 429

"Page-Specific Javascript" using stimulusjs on rails

May I know, can we achieve "Page-Specific Javascript" loading as mentioned in Organizing Javascript in Rails Application With Turbolinks article using the stimulusjs framework ?

Thanks.

Upvotes: 1

Views: 702

Answers (1)

Rolandas Barysas
Rolandas Barysas

Reputation: 360

Yes, though it's more "component-specific".

With Stimulus, you can add data-controller to any element, and at any time that elements is in the DOM, appropriate controller will be invoked. No need for $(document).ready or $(document).on("turbolinks:load") — everything happens automatically.

You can read more in Stimulus Handbook.

Upvotes: 1

Related Questions