Hi plugin-authors.
So this is a little bit of take two on this question, but why can’t I
access a singleton on the model calling my plugin? The crux of the full
plugin below is:
#logger.info self.class.to_s
new_copy = self.class.new( @copyable_attributes )
the logger spits out “Datatype”, but I get an error from rails saying:
undefined method `datatype’ for false:FalseClass
for the self.class.new line. I also feel haunted by the knowledge that
this is far easier than I think it is, though I cannot seem to find the
answer in the acts_as_versioned or any other plugin (since none create
new
instances of their calling model class).
full plugin contents follow.
whimper help?
–
Matthew B. :: 607 227 0871
Resume & Portfolio @ http://madhatted.com
ActsAsCopyable
module FakeActiveRecord
module Acts #:nodoc:
module Copyable #:nodoc:
def self.append_features(base)
super
base.extend(MacroMethods)
end
# declare the class level helper methods which
# will load the relevant instance methods
# defined below when invoked
module MacroMethods
def acts_as_copyable
include FakeActiveRecord::Acts::Copyable::InstanceMethods
end
end
# Adds instance methods.
module InstanceMethods
def copy( options = {} )
@copyable_attributes = self.attributes
@copyable_attributes.delete 'id'
options.each do |key, value|
next if key.class == String
options.delete key
options[key.to_s] = value
end
@copyable_attributes.merge! options
#logger.info self.class.to_s
new_copy = self.class.new( @copyable_attributes )
new_copy.save
end
end
end
end
end