Trying to add acts_as_list to Issue

Added by Mark Maglana over 8 years ago

I'm experimenting with plugins and tried to follow the instructions that Eric gave regarding extending Redmine's core models. The one thing I wanted to do is to make the Issue act as a list (acts_as_list). Here's what I did:

In init.rb

require 'redmine'

# Patches to the Redmine core
require 'issue_patch'

...

In lib/issue_patch.rb

require_dependency 'issue'

module IssuePatch
  def self.included(base) # :nodoc:
    base.extend(ClassMethods)

    base.send(:include, InstanceMethods)

    base.class_eval do
      unloadable
      acts_as_list :scope => :project
    end 
  end

  module ClassMethods

  end

  module InstanceMethods

  end

end

Issue.send(:include, IssuePatch)

I try this out in script/console with Issue.find(:first).insert_at and it works like a charm. However, when I try to do the same thing in one of my plugin's controllers, I get a NoMethodError:

undefined method `insert_at' for #<Issue:0x401b568>

What am I missing? :-)

Replies (4)

RE: Trying to add acts_as_list to Issue - Added by Mark Maglana over 8 years ago

ummm...sorry about that. I was missing

require 'application'

In my init.rb. I'm not quite sure what that does, but I'm just happy it works. What's it for?

RE: Trying to add acts_as_list to Issue - Added by Mark Maglana over 8 years ago

Hmmm...I take that back. Sometimes it works, sometimes it doesn't. What gives?

RE: Trying to add acts_as_list to Issue - Added by Mark Maglana over 8 years ago

Fixed by adding this to init.rb

require 'dispatcher'
Dispatcher.to_prepare do
  Issue.send(:include, Backlogs::IssuePatch)
end

RE: Trying to add acts_as_list to Issue - Added by Eric Davis over 8 years ago

For others who run into this:

I've done a blog post that shows what's happening internally along with how to fix it: http://theadmin.org/articles/2009/4/13/how-to-modify-core-redmine-classes-from-a-plugin

Eric Davis

(1-4/4)