stimulusreflex / stimulus_reflex

Build reactive applications with the Rails tooling you already know and love.
https://docs.stimulusreflex.com
MIT License
2.28k stars 172 forks source link

`stimulus_reflex:install` fails to complete in Rails 5.2 #367

Closed Matt-Yorkley closed 3 years ago

Matt-Yorkley commented 3 years ago

Bug Report

Describe the bug

Fatal error in stimulus_reflex:install task in Rails 5.2.

To Reproduce

  1. Generate a fresh Rails app with 5.2
  2. Go through the simple steps in the setup guide
  3. bundle exec rails stimulus_reflex:install mostly completes, but hits a fatal error and misses out a few bits of the install process

Expected behavior

Setup succeeds in Rails 5.2

Screenshots or reproduction

...snip
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 5 new dependencies.
info Direct dependencies
└─ stimulus_reflex@3.3.0
info All dependencies
├─ @rails/actioncable@6.0.3
├─ cable_ready@4.3.0
├─ form-serialize@0.7.2
├─ morphdom@2.6.1
└─ stimulus_reflex@3.3.0
Done in 6.24s.
mkdir -p /home/user/myproject/app/javascript/controllers
mkdir -p /home/user/myproject/app/reflexes
Updating /home/user/myproject/app/javascript/controllers/index.js
rails aborted!
NoMethodError: undefined method `module_parent' for Myproject::Application:Class
Did you mean?  module_eval
/home/user/myproject/bin/rails:9:in `<top (required)>'
/home/user/myproject/bin/spring:15:in `require'
/home/user/myproject/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => stimulus_reflex:install
(See full trace by running task with --trace)

The call to #module_parent in line 61 in lib/stimulus_reflex/tasks/install.rake causes the exception. Looks like the method is only available in ActiveSupport 6+.

Versions

StimulusReflex

External tools

Ruby 2.5.7 Rails 5.2.4.4 Node: 10.19.0

Browser

leastbad commented 3 years ago

Hi Matt, thanks for reporting this. The documentation can and will be clearer that this is an install for Rails 6+.

There is a section on Rails 5.2 further down on the same page... did you see it? https://docs.stimulusreflex.com/setup#rails-5-2-support

Matt-Yorkley commented 3 years ago

Yes, I just thought there might be simple way to replace that method call that would make it work in both versions..?

It's just being used to write a lower-case string with the name of the current project: https://github.com/hopsoft/stimulus_reflex/blob/5c39c91ceec3c8a27520568128f51d4204f1f945/lib/tasks/stimulus_reflex/install.rake#L63

leastbad commented 3 years ago

Oh, I see what you mean. Let me look into this.

Matt-Yorkley commented 3 years ago

Eg: File.basename(Rails.root.to_s).underscore would give you the same result as Rails.application.class.module_parent.to_s.underscore, and the installer would succeed in 5.2 and 6

leastbad commented 3 years ago

Hey, I encourage you to whip up a PR so you get credit!