New Engine Model extension content

107 views
Skip to first unread message

Weston Platter

unread,
Jul 22, 2012, 5:29:43 PM7/22/12
to rubyonra...@googlegroups.com
I added content on how to extend Rails Engine models. Please feel free to review and provide feedback.

Ryan Bigg

unread,
Jul 22, 2012, 6:10:49 PM7/22/12
to rubyonra...@googlegroups.com
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

On Monday, 23 July 2012 at 7:29 AM, Weston Platter wrote:

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Documentation" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-docs/-/IJBXpYpa0skJ.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-do...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-docs?hl=en.

Les Nightingill

unread,
Jul 22, 2012, 6:30:24 PM7/22/12
to rubyonra...@googlegroups.com
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

Ryan Bigg

unread,
Jul 22, 2012, 6:32:23 PM7/22/12
to rubyonra...@googlegroups.com
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.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Documentation" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-docs/-/IgoWqn2wO7QJ.

Les Nightingill

unread,
Jul 22, 2012, 6:58:49 PM7/22/12
to rubyonra...@googlegroups.com
oops thanks for the clarification, Ryan. Indeed I misinterpreted the code. Sorry Weston!


On Sunday, July 22, 2012 3:32:23 PM UTC-7, Ryan Bigg wrote:
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.

On Monday, 23 July 2012 at 8:30 AM, Les Nightingill wrote:

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

On Sunday, July 22, 2012 2:29:43 PM UTC-7, Weston Platter wrote:
I added content on how to extend Rails Engine models. Please feel free to review and provide feedback.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Documentation" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-docs/-/IgoWqn2wO7QJ.
To post to this group, send email to rubyonrails-docs@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-docs+unsubscribe@googlegroups.com.

Weston Platter

unread,
Jul 24, 2012, 5:13:56 AM7/24/12
to rubyonra...@googlegroups.com
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).

Ryan Bigg

unread,
Jul 25, 2012, 2:36:23 AM7/25/12
to rubyonra...@googlegroups.com
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?
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-docs/-/VleBHY_uRy4J.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-do...@googlegroups.com.

Weston Platter

unread,
Jul 25, 2012, 8:52:04 AM7/25/12
to rubyonra...@googlegroups.com
I agree. 

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

Weston Platter

unread,
Aug 4, 2012, 8:16:20 PM8/4/12
to rubyonra...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages