Created
August 8, 2020 18:17
-
-
Save Syntaf/623f9a09c2ef202c129245de7f8c0855 to your computer and use it in GitHub Desktop.
Dynamically reloads rails_admin configuration that lives within model concerns.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class ApplicationController < ActionController::Base | |
before_action :reload_rails_admin, if: :rails_admin_path? | |
private | |
def reload_rails_admin | |
RailsAdmin::Config.reset | |
load(Rails.root.join('config/initializers/rails_admin.rb')) | |
models = %w[Overseer Moderator Group Info Location Submitter] | |
models.each do |m| | |
Object.send(:remove_const, m) | |
file_path = m.to_s.underscore | |
load(Rails.root.join("app/models/#{file_path}.rb")) | |
end | |
end | |
def rails_admin_path? | |
controller_path =~ /rails_admin/ && Rails.env.development? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment