nil object exception after hack issue model

Added by Kirill Bezrukov (RedmineUP) over 7 years ago

I wrote one more customers plugin. But I have problem to join issues and customers. I use patch to add relation has_and_belongs_to_many :contacts, but it works only one time. After raises exception undefined method `contacts' for issue

It works great to link customer.issues, but issue. contacts raises error after first time, and I need reload app

I make this patches

require_dependency 'issue'   
require_dependency 'issues_controller'

# Patches Redmine's Issues dynamically. Adds a relationship
# Issue +has_many+ to ArchDecisionIssue
# Copied from dvandersluis' redmine_resources plugin: 
# http://github.com/dvandersluis/redmine_resources/blob/master/lib/resources_issue_patch.rb
module ContactsIssuePatch
  def self.included(base) # :nodoc:
    # Same as typing in the class
    base.class_eval do    
      unloadable # Send unloadable so it will not be unloaded in development
      has_and_belongs_to_many :contacts, :order => "last_name, first_name" 
    end
  end
end     

module ContactsIssuesControllerPatch
 def self.included(base) # :nodoc:
    base.class_eval do
      unloadable # Send unloadable so it will not be unloaded in development
    end
  end
end

Issue.send(:include, ContactsIssuePatch)
IssuesController.send(:include, ContactsIssuesControllerPatch) 

Replies (1)

RE: nil object exception after hack issue model - Added by Kirill Bezrukov (RedmineUP) over 7 years ago

I've got how to make it


Dispatcher.to_prepare do
  Issue.send(:include, ContactsIssuePatch)    
end  

(1-1/1)