Defect #26636


Rails 5: "Page not found" error when accessing a page of a plugin in production mode

Added by Go MAEDA almost 7 years ago. Updated over 5 years ago.

Plugin API
Target version:
Start date:
Due date:
% Done:


Estimated time:
Affected version:


Steps to reproduce:

1. Create a test plugin.

bin/rails g redmine_plugin foo
bin/rails g redmine_plugin_controller foo foo index
echo 'get "foo", :to => "foo#index"' >> plugins/foo/config/routes.rb

2. Run Redmine in production mode

bin/rails s -e production

3. Open http://localhost/foo and you will see "Page not found" error. No problem in development mode.



Related issues

Related to Redmine - Feature #23630: Migrate to Rails 5.2ClosedJean-Philippe Lang

Related to Redmine - Patch #30725: Plugin eager_load should depend on environment setting instead of nameClosedGo MAEDA

Actions #1

Updated by Go MAEDA almost 7 years ago

  • Target version set to 4.0.0
Actions #2

Updated by Go MAEDA almost 7 years ago

  • Description updated (diff)
Actions #3

Updated by Akiko Takano almost 7 years ago

Hi, I'm triyng to port my plugins, from Redmine 3.4 to Redmine trunk (ver4.0, based on Rails5).
I managed to port my plugin to support Rails5, and it seems works fine under development / test environment.

But under production mode, I saw the same error.
When I try to access one of plugin's controller, error happened and the message such as "uninitialized constant xxxxxxxController” was recorded.

I personally think, it seems required files under plugin's directory are not loaded in production mode.
And also think this is because autoload definition is disabled for production mode in Rails 5 by default.


Here is my workaround and I am glad if they were helpful.

Workaround 1: Enabled autoload in production mode

$ hg diff config/application.rb 
diff -r 95623038cf82 config/application.rb
--- a/config/application.rb    Mon Jul 24 17:14:53 2017 +0000
+++ b/config/application.rb    Fri Aug 04 23:35:24 2017 +0900
@@ -12,6 +12,7 @@

     # Custom directories with classes and modules you want to be autoloadable.
     config.autoload_paths += %W(#{config.root}/lib)
+    config.enable_dependency_loading = true

     # Only load the plugins named here, in the order given (default is alphabetical).
     # :all can be used as a placeholder for all plugins not explicitly named.

Workaround 2: Add plugin's directory to eager_load_paths at lib/redmine/plugin.rb

When application boots in production then the application loads all constants found in all directories listed in eager_load_paths.

$ hg diff lib/redmine/plugin.rb 
diff -r 95623038cf82 lib/redmine/plugin.rb
--- a/lib/redmine/plugin.rb    Mon Jul 24 17:14:53 2017 +0000
+++ b/lib/redmine/plugin.rb    Fri Aug 04 23:38:31 2017 +0900
@@ -93,6 +93,7 @@
       # Adds the app/{controllers,helpers,models} directories of the plugin to the autoload path
       Dir.glob File.expand_path(File.join(, 'app', '{controllers,helpers,models}')) do |dir|
         ActiveSupport::Dependencies.autoload_paths += [dir]
+        Rails.application.config.eager_load_paths += [dir] if Rails.env == 'production'

       # Defines plugin setting if present

I personally prefer the second way.

Actions #4

Updated by Jean-Philippe Lang about 6 years ago

  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Resolution set to Fixed

Second fix committed, thanks.

Actions #5

Updated by Marius BĂLTEANU about 6 years ago

Actions #6

Updated by Enziin System about 6 years ago

The second way doesn't work for me.

Please use both ways.

Actions #7

Updated by Go MAEDA about 6 years ago

Enziin System wrote:

The second way doesn't work for me.

Could you describe more detail?

Actions #8

Updated by Marius BĂLTEANU over 5 years ago

  • Target version deleted (4.0.0)

I'm removing this ticket from the Changelog because it was a problem generated by the migration to Rails 5 (we did the same thing with the others tickets).

Actions #9

Updated by Go MAEDA over 5 years ago

  • Related to Patch #30725: Plugin eager_load should depend on environment setting instead of name added

Also available in: Atom PDF