Stimulus Namespace
Prefix every Stimulus identifier the gem emits so the gem's controllers coexist with your app's controllers of the same name. Available in v0.47.0+.
Why it exists
RapidRails UI is a Stimulus-coupled component library. The gem ships dozens of Stimulus controllers with natural
identifiers like dialog, menu, checkbox, search,
upload. Most non-trivial Rails apps already declare Stimulus controllers of their own. If both sides
register the same identifier, Stimulus picks one and the other silently breaks: components render fine but their
triggers do nothing.
config.stimulus_namespace prefixes the gem's identifiers (e.g. dialog →
rui--dialog) so the two sides stop fighting. The prefix propagates through every emission point:
data-controller, data-action, data-X-target, data-X-Y-value.
Recommended for any app that ships more than a handful of its own Stimulus controllers. If your app has no overlap with the gem's identifiers, the default (no namespace) is simpler and keeps identifiers short.
Enabling the namespace
Easiest path: re-run the install generator with the --stimulus-namespace flag. It bakes the value
into the initializer and rewrites application.register(...) calls in
app/javascript/controllers/index.js so the Ruby and JS sides stay in sync.
rails g rapid_rails_ui:install --stimulus-namespace=rui
Or set it manually in the initializer (you'll need to update index.js yourself):
RapidRailsUI.configure do |config|
config.stimulus_namespace = "rui"
end
What changes in emitted HTML
<div data-controller="dialog"
data-dialog-open-on-load-value="false">
<button data-action="dialog#open" data-dialog-target="trigger">Open</button>
</div>
<div data-controller="rui--dialog"
data-rui--dialog-open-on-load-value="false">
<button data-action="rui--dialog#open" data-rui--dialog-target="trigger">Open</button>
</div>
What changes in your controllers/index.js
The identifier passed to application.register must match the identifier the ERB emits. The install
generator handles this for you. If you flipped the config by hand, edit index.js too:
import DialogController from "./rapid_rails_ui/dialog_controller"
application.register("dialog", DialogController)
import DialogController from "./rapid_rails_ui/dialog_controller"
application.register("rui--dialog", DialogController)
What changes in your own templates
Any custom data-action, data-X-target, or data-X-Y-value attribute you
write that references a gem controller must use the namespaced identifier. The most common case: a trigger button
outside the component's slot.
WRONG — silently does nothing when stimulus_namespace is set:
<button data-action="dialog#open">Open</button>
RIGHT — either form works:
<button data-action="rui--dialog#open">Open</button>
<%# Or, with the helper (recommended — adapts to whatever you configure): %>
<button data-action="<%= stimulus_action(:dialog, "click->#open") %>">Open</button>
Helpers (for portable code)
The gem mixes RapidRailsUI::Helpers::StimulusHelper into BaseComponent. Use these
helpers in your own ERB or components and your code is correct under both default and namespaced configs:
stimulus_id(:dialog)
# => "dialog" (no namespace)
# => "rui--dialog" (namespace = "rui")
stimulus_action(:dialog, "click->#open")
# => "click->dialog#open"
# => "click->rui--dialog#open"
stimulus_attr(:dialog, :target)
# => :"dialog-target"
# => :"rui--dialog-target"
stimulus_attr(:dialog, :open_on_load_value)
# => :"dialog-open-on-load-value"
# => :"rui--dialog-open-on-load-value"
Known caveat in v0.47.0
On v0.47.0, a handful of internal component templates still emit hardcoded unnamespaced action strings
(data-action="dialog#close", data-action="dialog#backdropClick", and equivalents in
Dialog, Pagination, and Steps). If you set
config.stimulus_namespace, your own custom triggers work, but the gem's built-in close /
backdrop / paginate handlers may not fire. Fixed in the next release; until then, either don't set the
namespace on the affected components or ship a small shim that listens to the gem's events.
Troubleshooting
Component renders but interactions do nothing (no JS console errors).
See the dedicated Troubleshooting page for the full diagnosis ladder.