Closed wJoenn closed 1 year ago
Scrap this, it was raised to my attention that this could have conflicts if any other javascript/controllers directory exist. I'll work on a different way that would use the config file of Rails. Something like
config.generators do |generate|
generate.stimulus_path "path/to/controllers"
end
In the end I created a stimulus initializer file in which I can configurate the path by doind
Stimulus.configure do |config|
config.controllers_path = "path/to/controllers"
end
The value of Stimulus.controllers_path
is then read in the generator and task to respect the user's preference
@dhh May I ask why ?
I am using vite_rails in my project and because of that I don't have a app/javascript folder but a app/frontend/javascript folder. Because the path in the Stimulus generator is hardcoded every time I try to use it to generate a new controller it would recreate the app/javascript folder and add the controller there instead of inside my existing folder.
Here's a fix that would make any file structure compatible by using
Dir.glob("**/javascript/controllers").first
instead of"app/javascript/controllers"
I tested it locally and it's working as expected as far as I can see