Overriding Models


Hi list.

I know that it is currently hard to override anything in the model
classes of an Engine. What about the following:

Engines includes the file RAILS_ROOT/app/components/engine_models.rb
after the last model require. In this file, you can have code like:

class MyModel
has_many :foo

So you can mix in code there.

Would this work, James?




I’m not very keen on putting models in files other than
<model_name>.rb, since this fits best with Rails’ own scheme and will
work with the auto-dependency loading too. The ‘best practice’ at the
moment is to only provide stub models in your engine, and use meta
programming along with modules to include functionality. Take a look
at the login/user engines’ User model classes for an example of this.

The advantage of doing it this way is that an end-user-developer can
override methods by creating their own model class, adding the
‘include’ lines and then redefining any methods that they want. It’s
not perfect, but it’s literally only a couple of lines more than the
controlller/helper mixing.

  • james

On 3/4/06, Manuel H. removed_email_address@domain.invalid wrote:

engine-developers mailing list

  • J *