Project

General

Profile

Actions

Defect #38021

closed

Development mode, class-reloader is not work.

Added by Haihan Ji about 2 years ago. Updated about 2 years ago.

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

Is duplicate of Redmine - Defect #36273: Modifying the source code of a plugin does not reload it after r21295ClosedGo MAEDA

Actions
Actions #1

Updated by Dmitry Makurin about 2 years ago

It has been broken since #32938, the issue already was reported #36273.
Rails does not track files changes under plugin/ directory, reloading still works if redmine core modified but not the plugin ones.

Actions #2

Updated by Go MAEDA about 2 years ago

  • Is duplicate of Defect #36273: Modifying the source code of a plugin does not reload it after r21295 added
Actions #3

Updated by Go MAEDA about 2 years ago

  • Status changed from New to Closed
  • Resolution set to Duplicate

Fixed by #36273 for Redmine 5.0.5.

Actions

Also available in: Atom PDF