Models...revisited

Reviving a 2 year old thread, how is everyone extending their models in
engines these days?

I’m attempting to move Substruct to a module system as described here:
http://www.ruby-forum.com/topic/51339

…but I’m getting a ton of errors like this one:

“undefined method `has_and_belongs_to_many’ for Substruct::Tag:Module”

So what good is that method if you have to redeclare the associations in
the class, and not within the module itself?

Any ideas or tricks that people are using to get around this? Copying /
pasting models into app/models to extend is getting tiresome, but this
workaround seems pretty hackish as well.

Peter B. wrote:

On Mon, Sep 17, 2007 at 05:48:08AM +0200, Subimage Interactive wrote:
require_dependency RAILS_ROOT + “vendor/plugin/my_plugin/app/models/foo”

class Foo < ActiveRecord::Base

extend here

end

Many thanks…syntax was a bit off, but easily corrected.

require_dependency RAILS_ROOT +
“/vendor/plugins/substruct/app/models/order”

class Order < ActiveRecord::Base
def promotion_code
if self.promotion
return self.promotion.code
else
return “W001”
end
end

end

On Mon, Sep 17, 2007 at 05:48:08AM +0200, Subimage Interactive wrote:

So what good is that method if you have to redeclare the associations in
the class, and not within the module itself?

Any ideas or tricks that people are using to get around this? Copying /
pasting models into app/models to extend is getting tiresome, but this
workaround seems pretty hackish as well.

See Extending models from engines - Engines Development - Ruby-Forum. This turned out not to work
100%,
as we found out in Problem with assocations - Engines Development - Ruby-Forum

Short and simple:

In app/models/foo.rb:

require_dependency RAILS_ROOT + “vendor/plugin/my_plugin/app/models/foo”

class Foo < ActiveRecord::Base

extend here

end

Hope this helps,
Peter B.
Solide ICT - http://www.solide-ict.nl