Introducing OpalStimulus! 🎉
Joseph Schito

Joseph Schito @josephschito

Location:
Milan, Italy
Joined:
Sep 6, 2022

Introducing OpalStimulus! 🎉

Publish Date: Jun 19
4 5

Have you ever dreamed of being able to write your Stimulus controllers in Ruby instead of JavaScript?
Here's OpalStimulus, a Stimulusjs wrapper for Opal, with a Rails installer.
Obviously for now (while being functional) this project is still in development and not complete, but if you want to contribute or simply try it out, you can do so https://github.com/josephschito/opal_stimulus/pulls

Here's a small example of how it works:

Basic Example

Here's a Hello World example with OpalStimulus. Compare with the original Stimulus example.

Add this line to your Gemfile:

gem 'opal_stimulus'
Enter fullscreen mode Exit fullscreen mode

Run:

bundle install
rails generate opal_stimulus:install
Enter fullscreen mode Exit fullscreen mode

Start the application:

bin/dev
Enter fullscreen mode Exit fullscreen mode

Create app/opal/controllers/hello_controller.rb and fill it with:

class HelloController < StimulusController
  self.targets = ["name", "output"]
  def greet
    output_target.text_content = "Hello, #{name_target.value}!"
  end
end
Enter fullscreen mode Exit fullscreen mode

Add this to a view:

<div data-controller="hello">
  <input data-hello-target="name" type="text">
  <button data-action="click->hello#greet">
    Greet
  </button>
  <span data-hello-target="output">
  </span>
</div>
Enter fullscreen mode Exit fullscreen mode

Result:

Enjoy! 😉

Comments 5 total

  • sebyx07
    sebyx07Jun 20, 2025

    too much overhead of having the code full of .JS[]

    • Joseph Schito
      Joseph SchitoJun 21, 2025

      I totally agree with you!
      This is a very early version, I’ll definitely remove them soon.

  • Nevo David
    Nevo DavidJun 20, 2025

    honestly this is huge for me since i never vibe with js that much. makes me wonder - you think stuff like this actually helps keep dev life fun, or does it just make us lazier over time?

Add comment