Describe the bug
In app/assets/javascripts/rails_admin/application.js.erb, there is detection for the use of ActionText:
|
<% if defined?(ActionText) && Rails.gem_version >= Gem::Version.new('7.0') %> |
|
//= require trix |
|
//= require actiontext |
|
<% end %> |
This checks if the ActionText module exists by calling defined?.
My application does not use ActionText, but the ActionText module exists for other reasons. For me, this gets loaded by bootstrap_form gem, which uses the ERB helpers only:
https://github.com/bootstrap-ruby/bootstrap_form/blob/ed3eda885c2145a364e8affd759f42b03ff6ee7c/lib/bootstrap_form.rb#L1-L9
When Rails bootstrap_form loads the global module ActionText for its helpers, it "tricks" railsadmin into believing ActionText is in use, which causes and issue when compiling assets:
$ bundle exec rails assets:precompile
bin/rails aborted!
Sprockets::FileNotFound: couldn't find file 'trix' with type 'application/javascript' (Sprockets::FileNotFound)
Checked in these paths:
.../app/assets/config
.../app/assets/images
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/app/assets/stylesheets
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/vendor/assets/fonts
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/vendor/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/vendor/assets/stylesheets
.../vendor/bundle/ruby/3.2.0/gems/turbo-rails-1.5.0/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/nested_form-0.3.2/vendor/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/bootstrap_form-5.4.0/app/assets/stylesheets
.../vendor/bundle/ruby/3.2.0/gems/actioncable-7.1.2/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/activestorage-7.1.2/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/actionview-7.1.2/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/actionview-7.1.2/lib/assets/compiled
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/src
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/app/assets/javascripts/rails_admin/application.js.erb:24
Reproduction steps
- Modify your project's
config/application.rb to not require "action_text/engine"
- Include bootstrap_form gem in the project
- Compile assets with
bundle exec assets:precompile
Expected behavior
Assets are compiled and the ActionText dependencies are skipped.
Is there a more robust approach to detecting ActionText was loaded?
Additional context
rails version: 7.1.2
rails_admin version: 3.1.2
rails_admin npm package version: n/a
- full stack trace (if there's an exception)
$ bundle exec rails assets:precompile
bin/rails aborted!
Sprockets::FileNotFound: couldn't find file 'trix' with type 'application/javascript' (Sprockets::FileNotFound)
Checked in these paths:
.../app/assets/config
.../app/assets/images
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/app/assets/stylesheets
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/vendor/assets/fonts
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/vendor/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/vendor/assets/stylesheets
.../vendor/bundle/ruby/3.2.0/gems/turbo-rails-1.5.0/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/nested_form-0.3.2/vendor/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/bootstrap_form-5.4.0/app/assets/stylesheets
.../vendor/bundle/ruby/3.2.0/gems/actioncable-7.1.2/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/activestorage-7.1.2/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/actionview-7.1.2/app/assets/javascripts
.../vendor/bundle/ruby/3.2.0/gems/actionview-7.1.2/lib/assets/compiled
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/src
.../vendor/bundle/ruby/3.2.0/gems/rails_admin-3.1.2/app/assets/javascripts/rails_admin/application.js.erb:24
Describe the bug
In
app/assets/javascripts/rails_admin/application.js.erb, there is detection for the use of ActionText:rails_admin/app/assets/javascripts/rails_admin/application.js.erb
Lines 27 to 30 in 13c90fd
This checks if the
ActionTextmodule exists by callingdefined?.My application does not use ActionText, but the ActionText module exists for other reasons. For me, this gets loaded by
bootstrap_formgem, which uses the ERB helpers only:https://github.com/bootstrap-ruby/bootstrap_form/blob/ed3eda885c2145a364e8affd759f42b03ff6ee7c/lib/bootstrap_form.rb#L1-L9
When Rails bootstrap_form loads the global module
ActionTextfor its helpers, it "tricks" railsadmin into believing ActionText is in use, which causes and issue when compiling assets:Reproduction steps
config/application.rbto notrequire "action_text/engine"bundle exec assets:precompileExpected behavior
Assets are compiled and the ActionText dependencies are skipped.
Is there a more robust approach to detecting ActionText was loaded?
Additional context
railsversion: 7.1.2rails_adminversion: 3.1.2rails_adminnpm package version: n/a