Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:52:36+00:00 2026-05-26T14:52:36+00:00

Using Rails 2.3.11 , I’m creating a plugin for Redmine that add methods to

  • 0

Using Rails 2.3.11, I’m creating a plugin for Redmine that add methods to ApplicationController.

I’ve created the following module, in the plugin :

module ApplicationControllerPatch
  def self.included(base) # :nodoc:
    base.class_eval do
      rescue_from AnException, :with => :rescue_method

      def rescue_method(exception)
        ...
      end
    end
  end
end

Now, if I include this module directly into the application_controller.rb file, like this:

class ApplicationController < ActionController::Base
  include ApplicationControllerPatch

  ...
end

Everything works just fine, however I would like to avoid editing the core source by including this module from the plugin itself.
So far, if I do:

ApplicationController.send(:include, ApplicationControllerPatch)

directly from this module file (located in the plugin folder). This will load properly for the request and then it gets overwritten by the controller (I guess).

What’s is the way to accomplish this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:52:36+00:00Added an answer on May 26, 2026 at 2:52 pm

    A common pattern is to use Dispatcher.to_prepare inside your plugin’s init.rb. This is required because in development mode (or generally if config.cache_classes = false) Rails reloads all classes right before each request to pick up changes without the need to completely restart the application server each time.

    This however means the you have to apply your patch again after the class got reloaded as Rails can’t know which modules got injected later on. Using Dispatcher.to_prepare you can achieve exactly that. The code defined in the block is executed once in production mode and before each request in development mode which makes it the premier place to monkey patch core classes.

    The upside of this approach is that you can have your plugins self-contained and do not need to change anything in the surrounding application.

    Put this inside your init.rb, e.g. vendor/plugins/my_plugin/init.rb

    require 'redmine'
    
    # Patches to the Redmine core.
    require 'dispatcher'
    
    Dispatcher.to_prepare do
      ApplicationController.send(:include, MyPlugin::ApplicationControllerPatch) unless ApplicationController.include?(RedmineSpentTimeColumn::Patches::IssuePatch)
    end
    
    Redmine::Plugin.register :my_plugin do
      name 'My Plugin'
      [...]
    end
    

    Your patch should always be namespaced inside a module named after your plugin to not run into issues with multiple plugins defining the same module names. Then put the patch into lib/my_plugin/application_controller_patch.rb. That way, it will be picked up automatically by the Rails Autoloader.

    Put this into vendor/plugins/my_plugin/lib/my_plugin/application_controller_patch.rb

    module MyPlugin
      module ApplicationControllerPatch
        def self.included(base) # :nodoc:
          base.class_eval do
            rescue_from AnException, :with => :rescue_method
    
            def rescue_method(exception)
              [...]
            end
          end
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Rails v2.1, lets say you have an action for a controller that is
I am using Rails 2.3 and I decided to provide support for JSONP. Created
I'm using rails 2.3.4 When I execute rake db:test:prepare the id field created is
Using Rails 3.1.0 def create @practice = Practice.new(params[:practice]) respond_to do |format| if (current_user.practices <<
Using Rails, I would like to add: <span class='req'>&bull;</span> within my <label> tags in
I am using Rails 2.2.2 and I would like to add an id to
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
(Using Rails 3.1.3) I have an app that manages products. I import the products
using rails with Paperclip, I can use the following to get the filename during
using rails 3.0.1 and ruby 1.9.2-p0 in the rails console I'm seeing the following:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.