Actions
Defect #38021
closedDevelopment mode, class-reloader is not work.
Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:
0%
Estimated time:
Resolution:
Duplicate
Affected version:
Description
http://127.0.0.1:3000/admin/info
Environment: Redmine version 5.0.4.stable Ruby version 2.6.9-p207 (2021-11-24) [x64-mingw32] Rails version 6.1.7 Environment development Database adapter Mysql2 Mailer queue ActiveJob::QueueAdapters::AsyncAdapter Mailer delivery smtp Redmine settings: Redmine theme Default SCM: Subversion 1.14.1 Git 2.34.1 Filesystem Redmine plugins: demo 0.0.1
make a plugin:
rails g redmine_plugin demo rails g redmine_plugin_controller demo test index
plugin/config/routes.rb
# Plugin's routes # See: http://guides.rubyonrails.org/routing.html resources 'test'
plugins/demo/app/controllers/test_controller.rb
class TestController < ApplicationController def index @var = 'abc' end end
plugins/demo/app/views/test/index.html.erb
<h2>TestController#index</h2> <h3>@var</h3> <%= debug @var%>
If I change value of @var, I have to reboot the server to make it effective.
I read the rails guide ( https://guides.rubyonrails.org/autoloading_and_reloading_constants.html ), made a simple try.
Append this line to REDMINE_ROOT/config/application.rb
config.autoload_paths << 'D:/Ruby/redmine-5.0.4/plugins/demo/app/controllers'
Class Reloader work again!
Maybe, PluginLoader::add_autoload_paths
need upgrade, it seems that it does not work properly in Zeitwerk mode.
REDMINE_ROOT/lib/redmine/plugin_loader.rb:130
def self.add_autoload_paths
directories.each do |directory|
# Add the plugin directories to rails autoload paths
engine_cfg = Rails::Engine::Configuration.new(directory.to_s)
engine_cfg.paths.add 'lib', eager_load: true
engine_cfg.eager_load_paths.each do |dir|
Rails.autoloaders.main.push_dir dir # <== Here??
end
end
end
Related issues
Actions