Forum: Rails Engines Models...revisited

Posted by seth b. (subimage)
on 2007-09-17 05:48
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.
Posted by Peter Bex (Guest)
on 2007-09-17 13:24
(Received via mailing list)
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 http://www.ruby-forum.com/topic/98597.  This turned out not to work 
100%,
as we found out in http://www.ruby-forum.com/topic/99211

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 Bex
Solide ICT - http://www.solide-ict.nl
Posted by seth b. (subimage)
on 2007-09-20 09:36
Peter Bex 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


Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.