views:

185

answers:

2

I Have an engine in vendor/plugins. My problem is, that i seemingly can´t extend the engine-model with a model in the base application.

My folder structure:

APPNAME
 -app
  -models
   -item.rb
 -vendor
  -plugins
   -image_gallery
    -app
     -models
      -image_gallery.rb

Nothing special... in my image_gallery.rb i have just this:

class ImageGallery < Item
end

But Rails complains about missing methods which are defined in item.rb. If i define them in the image_gallery.rb, it works.

+1  A: 

I believe this is a load order problem. The vendor directory doesn't get reloaded in development mode. The model in your app hasn't been loaded when you engine model tries to inherit from it.

Sorry I don't know a fix for this and have never found one. I think rails 3 will be addressing this. We normally just keep the related models in the same engine or move the engine stuff up into the main app to avoid it. This sucks and I would love to know the proper solution.

Try in production mode and you shouldn't have the issue. You could look at using shotgun if this is the case.

tsdbrown
Thanks for your answer, tsdbrown, that´s exactly the problem. I think i should develop on application-base and swap the files later to an engine. Or restart my server after every change..
Arne Cordes
A: 

You can try to set config.cache_classes = true in your development.rb

Nils Riedemann
Has this worked for you in the past?
tsdbrown
Since the only relating difference in the development.rb compared to production.rb is this, i guessed so... yet, this leads to other annoyances but makes the code work.
Nils Riedemann
This works, thanks. The only problem is that you have to restart the server after every change.
Arne Cordes