Forums » Development »
Extend a Issue Model Function
Added by Nico Landgraf over 11 years ago
Hello,
I created a Plugin to import some stuff in Redmine and now it is required to extend a Model function in the Issue-Model (the update_closed_on).
So I checked the Development Guide and found some Code exampels but my Plugin code was not called.
I write the code direct in the Model to check if the syntax was wrong but all works fine.
I performed the follwing Steps:
- Create a Plugin in Plugins folder
- Create a File issue_patch.rb in the lib folder from the Plugin
- Add the following code to the 'issue_patch.rb'
require_dependency 'issue'
module IssuePatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
alias_method_chain :update_closed_on, :update_closed_on_with_patch
end
end
module InstanceMethods
def update_closed_on_with_patch
test = CustomValue.where("customized_id = #{self.id} AND customized_type = 'Issue' AND custom_field_id = 36").first
if !test.nil?
test.value = Date.today
test.save
end
end
end
end
Issue.send(:include, IssuePatch)
It seems to me that the code in my issue_patch was never called when the 'update_closed_on' was called.
Can anyone see a Problem un my function?