Forum: Rails Engines development Overriding Models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
54532f023496410e0d7b1add5561ba45?d=identicon&s=25 Manuel Holtgrewe (Guest)
on 2006-03-04 12:18
(Received via mailing list)
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
   end

So you can mix in code there.

Would this work, James?


Regards,

Manuel
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-03-06 17:05
(Received via mailing list)
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 Holtgrewe <purestorm@ggnore.net> wrote:
>    end
> engine-developers mailing list
> engine-developers@lists.rails-engines.org
> http://lists.rails-engines.org/listinfo.cgi/engine...
>


--
* J *
  ~
This topic is locked and can not be replied to.