Hi all,
I''m trying to throw together an acts_as_copyable, to add the ability
to:
@new_ar_object = @ar_object.copy
I''m using the Fox example for the basic loading into AR with a module:
http://wiki.rubyonrails.org/rails/pages/HowToWriteAnActsAsFoxPlugin
so in my 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.send :new, copyable_attributes
new_copy.save
end
end
Originally I was calling self.create, but that failed as well. Rails is
tossing my to an error page claiming:
undefined method `datatype'' for false:FalseClass
however, in my log, the self.class.to_s is Datatype, which should load the
Datatype class. IRB shows this:
irb(main):001:0> class Foo
irb(main):002:1> def hello
irb(main):003:2> puts ''hello
irb(main):004:2'' ''
irb(main):005:2> end
irb(main):006:1> def self.whoa
irb(main):007:2> puts ''whoa''
irb(main):008:2> end
irb(main):009:1> end
=> nil
irb(main):010:0> a = Foo.new
=> #<Foo:0x402d862c>
irb(main):011:0> a.send :hello
hello
=> nil
irb(main):012:0> a.send :whoa
NoMethodError: undefined method `whoa'' for #<Foo:0x402d862c>
from (irb):12:in `send''
from (irb):12
from :0
irb(main):013:0> a.class.send :whoa
whoa
=> nil
So, why doesn''t self.class.send work the same in a rails plugin? Why
is
Datatype being changed to datatype, and being called as a method, not a
class definiton?
Thanks,
--
Matthew Beale :: 607 227 0871
Resume & Portfolio @ http://madhatted.com