-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecation warnings about initializer autoloading constants in Rails 6 #3190
Comments
Same warnings here... did you find any solution? |
Not so far. (RailsAdmin also seems to no longer work with the Pundit integration so I might need to move to another library altogether (getting errors |
Having debugging this quite a bit, I found out that all of those were autoloaded by the Personally, I've disabled it because it's not critical for my project. Hope it helps to fix the deprecation warning. |
Another issue related to Rails 6 autoloading is that if I define in
Then register it in
In Rails 5.2 it would load just fine. I'm not sure if it's auto-reloaded well though. But Rails 6 will complain on boot
That's because in I'm not sure why RailsAdmin does that, but weren't it constantize action classes on initialization, they would've been auto-reloadable! Currently, the solution to get rid of the deprecation warning regarding the action classes is to |
I'm using rails_admin 2.0.0 and rails 6.0.0. I get the same warning as @tinbka in above comment. Without doing require for custom action files above Doing require for custom action file triggers deprecation warning. |
I've run into this as well. After some searching it narrowed down to these lines in RailsAdmin::ApplicationController.class_eval do
def user_for_paper_trail
_current_user.try(:id) || _current_user
end
end Evaluating these lines causes the warnings to be shown. I was not sure how @tinbka solved it so I'll add my workaround. The following works for Rails 6.0 in API only mode:
# frozen_string_literal: true
# Dedicated application controller for RailsAdmin
class ApplicationAdminController < ActionController::Base
# Tell RailsAdmin which user changed something
def user_for_paper_trail
_current_user.try(:id) || _current_user
end
end
# frozen_string_literal: true
# Monkey patch AuditingAdapter to prevent setup loading classes in initializer
# See: https://github.com/sferik/rails_admin/issues/3190
class RailsAdmin::Extensions::PaperTrail::AuditingAdapter
def self.setup; end
end
# Rails admin configuration
RailsAdmin.config do |config|
# Which class should be used for the controllers
config.parent_controller = '::ApplicationAdminController'
## == PaperTrail ==
config.audit_with :paper_trail, 'User', 'PaperTrail::Version'
# Other config as usual from here
end |
I am seeing these warnings only when i run rspec after installing rails admin v2.0.0 |
e275012 should have fixed this. @sedubois @tinbka require 'rails_admin/config/actions/do_something'
RailsAdmin::Config::Actions.register(:do_something, 'RailsAdmin::Config::Actions::DoSomething') |
the problem persists following the indications of the wiki about creating a reusable action. I resolved copying in the initializer the content of
instead of
|
I have a Rails 5.2 app with RailsAdmin 2.0. When updating to Rails 6 with classic autoloader (not yet Zeitwerk) I get these warnings:
My
initializers/rails_admin.rb
looks like this:From what I understood the documentation basically says that constants should simply not be autoloaded in initializers:
https://guides.rubyonrails.org/autoloading_and_reloading_constants_classic_mode.html#autoloading-and-initializers
My understanding is that things would not work at all if I instead used Zeitwerk, which is the new default autoloader.
How should RailsAdmin be configured if constants cannot be autoloaded in the initializer any more?
The text was updated successfully, but these errors were encountered: