From the course: Hotwire: Reactive Ruby on Rails Applications

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Connecting to the controller

Connecting to the controller

- [Instructor] In this video, we are going to create the first stimulus controller. It can be created with a Rails generator, rails g stimulus controller_name. Once the controller is created, you first need to know about lifecycle callbacks. There are three. Initialize, which is executed only once when the controller is first instantiated, connect, which is executed each time a DOM element is connected to the controller, and disconnect, which is executed each time a DOM element disconnected to the controller. Stimulus controllers are stored in the directory app, JavaScript, controllers, and their name ends with controller. Here, you can see one controller already created. the hello controller. It's a controller that Ruby on Rails create automatically, with the intention of testing if stimulus is working correctly. It includes the connect method, and it only puts the text "Hello World!" to the element that connects.…

Contents