New Engine Model extension content

I added content on how to extend Rails Engine models. Please feel free to review and provide feedback.

https://github.com/lifo/docrails/commit/890b9dd4439986e306ec4fc0067a00effa606204

Thank you for doing some work on this Weston. I’ve left a comment here with my thoughts https://github.com/lifo/docrails/commit/890b9dd4439986e306ec4fc0067a00effa606204#commitcomment-1614240

These are interesting ideas, Weston, but it’s not at all clear to me that an engine is the appropriate place for model decorators. In my opinion, an engine should implement a major block of functionality (possibly re-usable) that is self-contained enough to warrant carving it out of the main app as a separate piece. If a decorator pattern makes sense, I feel that it should be within the main app. What is it that suggests using an engine for model extensions?

A related question that I don’t know the answer to is: are Rails engines reloaded for each request in development environment, or is it necessary to restart the server in order for changes to take effect?

cheers

Les

I think you may have mis-interpreted the text.

The engine is a separate component. These modifications are inside the application and are modifying the engine’s class.

I would not use an engine for model extensions for a main app, given the reasons you’ve already cited.

Rails engines are reloaded each request in development environment and it’s not necessary to restart the server in order for changes to take effect. This seems like something worth mentioning in the guide.

oops thanks for the clarification, Ryan. Indeed I misinterpreted the code. Sorry Weston!

Ryan can you explain this a little more? It sounds like you are saying you would not extend main application models by open classing them in the engine.

I would not use an engine for model extensions for a main app, given the reasons you’ve already cited.

Less, no worries at all. If I separated the code chunks into some like this, would it be more clear? (if you mis-read it, other people might do the same).

https://gist.github.com/3169009

I think that an engine’s purpose is to provide additional functionality to an application with new classes, not to extend ones that are already there. For that kind of thing, I think a gem is better suited for that. Why would something that extends a class need to be inside an engine? Do you have a use case?

I agree.

Engines should provide classes to the Main App. The Main app can choose to use, extend, and override the Engine classes.z

Edited http://edgeguides.rubyonrails.org/engines.html

explained how to add/override engine classes in the main rails app using decorator pattern via

  1. Class#class_eval

  2. ActiveSupport::Concern

Feedback is welcome.
https://github.com/lifo/docrails/commit/39674d1e90a99f40f591cf97064f1a17d0542dc1