problem with overwrite methods

Added by Dariusz Kowalski over 3 years ago

Hello,

I am trying to write plugin which overwrite 2 methods of app/model/issue.rb

I do this like in file: https://github.com/darioo/redmine_improved_subtasks/blob/master/lib/improved_subtasks/patches/issue_patch.rb

I see that this new code is not executed and RM works as if this was not included?

What I am doing wrong?

My version of RM is 2.5.1

Best Regards
DK

Replies (2)

RE: problem with overwrite methods - Added by Martin Denizet (redmine.org team member) over 3 years ago

Hi Dariusz,

The code you linked allows to extend the class (Add method and properties).
To override methods, you will want to use alias_method_chain.
You can check this example in which I wrap the settings action of the project controller.
alias_method_chain works as follow:
alias_method_chain :<method to override>, :<name of the override>

After that, you have to define the class method <method to override>_with_<name of the override> and you can still call the original method with: <method to override>_without_<name of the override>

Hope it helps,

Cheers,

(1-2/2)