0.0
The project is in a healthy, maintained state
Opal Stimulus provides a way to write Stimulus controllers in Ruby, leveraging the Opal compiler to convert Ruby code into JavaScript. This allows developers familiar with Ruby to use the Stimulus framework without needing to write JavaScript directly.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 3.9.0
~> 1.8.2
 Project Readme

Opal Stimulus for Rails

Opal Stimulus is a Stimulus wrapper made with Opal (a source-to-source Ruby to JavaScript compiler) that allows you to write Stimulus controllers in Ruby instead of JavaScript (It works only with Rails).

Installation

Add this line to your Gemfile:

gem 'opal_stimulus'

Execute:

bundle install
rails generate opal_stimulus:install

Start application:

bin/dev

Basic Example

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

Ruby Controller:

# app/opal/controllers/hello_controller.rb
# new controllers will be automatically added to app/opal/controllers_requires.rb
#   (ordered files load is not supported yet)
class HelloController < StimulusController
  self.targets = ["name", "output"]

  def greet
    output_target.content = "Hello, #{name_target.value}!"
  end
end

HTML:

<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>

Result

Screen.Recording.2025-06-19.at.11.19.18.mov

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/josephschito/opal_stimulus.

License

The gem is available as open source under the terms of the MIT License.