First off, thank you all for such a lovely framework. I've been using it in Rails projects and it's been an absolute joy.
Something that I came across during development the other day was a naming convention-related misunderstanding, where I'd be trying to reference a controller with camelCase in a data-action and nothing fired. The way I fixed this, of course, was to use dash-case in the data-action, but it made me wonder if there's merit to letting Stimulus Rails recognize controllers by the camelCase equivalent as well, given that's a standard convention in JavaScript.
For example. if we have a controller declared as:
// app/javascript/controllers/multi_word_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
logHello() {
console.log("Hello!")
}
}
The logHello method will not fire. Intuitively, I want to write the action declaration the second way, where I'm using camelCase for both the controller name as well as the method name.
First off, thank you all for such a lovely framework. I've been using it in Rails projects and it's been an absolute joy.
Something that I came across during development the other day was a naming convention-related misunderstanding, where I'd be trying to reference a controller with camelCase in a
data-action
and nothing fired. The way I fixed this, of course, was to use dash-case in thedata-action
, but it made me wonder if there's merit to letting Stimulus Rails recognize controllers by the camelCase equivalent as well, given that's a standard convention in JavaScript.For example. if we have a controller declared as:
And we try to use it in a view like:
This will correctly log
"Hello!"
in the console when the button is clicked. However, if the button element is declared as:The
logHello
method will not fire. Intuitively, I want to write the action declaration the second way, where I'm using camelCase for both the controller name as well as the method name.Would love to hear a maintainer's take on this!