Rails 2.0 Engines Plugin: belongs_to Methods Not Working

Engine-Users mailing list
[email protected]

I think the issue you’re describing is this - please correct me if I’m

  • Savage beast contains a User class
  • Your application is trying to re-open the User class to add methods to
  • However, when the application runs, none of your custom methods
    appear on the User class.

If this is the case, it sounds like a fairly common thing. The key is
that model classes are not (at the moment) automatically mixed in the
same way that Controllers and Helpers are.

Instead, you need to ensure that both the plugin class AND your
application class is loaded. Your application’s class should be higher
in the load path, so if you “require ‘user’”, it should be that
app/models/user.rb will be loaded, but you can check this put putting
some ‘puts’ statements in to check. If everything is as expected, you
should then be able to explicitly require the user class from the
Savage Beast plugin at the top of this file, and then re-open the
class to add your methods.

It’s possible that the Savage Beast plugin references its own User
class explicitly before you have the chance to load the one in your
application - again, puts statements will shine a light on what’s
going on behind the scenes.