I found the time to package the decorator pattern into a gem:
http://rubygems.org/gems/rails_engine_decorators
https://github.com/atd/rails_engine_decorators
Hope it is helpful.
El 22/07/12 23:31, Weston Platter escribió:
Added 2 strategies for extending Engine Models. Feedback is welcome.
https://github.com/lifo/docrails/commit/890b9dd4439986e306ec4fc0067a00effa606204
On Friday, July 20, 2012 4:20:48 AM UTC-4, atd wrote:
It seems pretty useful for other engines as well! Any chances to
be included in Rails?
On 13/07/12 06:00, Ryan Bigg wrote:
We're currently discussing the best way to do this on Forem's
issue #260 (https://github.com/radar/forem/pull/260
<https://github.com/radar/forem/pull/260>). Kunal there wants to
add methods to or modify the Forem::Post class, and so we're
going to go with the app/decorators directory for that.
On Friday, 13 July 2012 at 5:49 AM, Mark McSpadden II wrote:
There has been some work done on the edgeguides around this as
well. There are a few notes scattered throughout but I believe
this section is that you are looking for.
http://edgeguides.rubyonrails.org/engines.html#using-a-class-provided-by-the-application
<http://edgeguides.rubyonrails.org/engines.html#using-a-class-provided-by-the-application>
If that feels incomplete or lacking, please do contribute to
make it better.
Mark McSpadden
On Thu, Jul 12, 2012 at 3:46 PM, Richard Schneeman
<[email protected]
<mailto:[email protected]>> wrote:
For extending models (and controller methods) I use concerns:
https://github.com/schneems/wicked/tree/master/lib/wicked/controller/concerns
<https://github.com/schneems/wicked/tree/master/lib/wicked/controller/concerns>
Then you can include them in other classes or modules in your repo.
https://github.com/schneems/wicked/blob/master/lib/wicked/wizard.rb
<https://github.com/schneems/wicked/blob/master/lib/wicked/wizard.rb>
Then you can let your user know to add an `include` statement
in the readme.
https://github.com/schneems/wicked
<https://github.com/schneems/wicked>
class AfterSignupController < ApplicationController
include Wicked::Wizard
Some people like to automatically add methods to
ActiveRecord::Base or other similar classes, this allows them
to have a dsl like `acts_as_tree` but this just pollutes the
available methods, and makes me have to remember unneeded dsl
when we ruby already has this type of behavior included with
`include`
If you want to add methods directly to the
ApplicationController of an app you can add a
application_controller_helper.rb
https://github.com/schneems/opro/tree/master/lib/opro/controllers
<https://github.com/schneems/opro/tree/master/lib/opro/controllers>
You need to include it
require 'opro/controllers/application_controller_helper'
then you can define a helper method for it:
def self.include_helpers(scope)
ActiveSupport.on_load(:action_controller) do
include scope::ApplicationControllerHelper if
defined?(scope::ApplicationControllerHelper)
end
end
and finally in your engine:
initializer "opro.include_helpers" do
Opro.include_helpers(Opro::Controllers)
end
For extending controllers like devise i've done this:
https://github.com/schneems/opro/blob/master/lib/opro/rails/routes.rb
<https://github.com/schneems/opro/blob/master/lib/opro/rails/routes.rb>
You use the user supplied controller or fall back to a default
view.
Digging in the devise source as well can be tremendously
valuable, though slightly daunting the first time or two. Let
me know if you have some questions.
--
Richard Schneeman
http://heroku.com
@schneems <http://twitter.com/schneems>
On Thursday, July 12, 2012 at 2:12 PM, Weston Platter wrote:
Is there a "Rails Way" way for extending models and
controllers of rails engines?
The docs have TODO notes with no content for extending
controllers and models (see 5.2 and 5.3
http://guides.rubyonrails.org/engines.html
<http://guides.rubyonrails.org/engines.html>).
If there's preferred method, I would love to use it and I'll
update the docs.
--
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/q7XpeRAheHkJ
<https://groups.google.com/d/msg/rubyonrails-core/-/q7XpeRAheHkJ>.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:[email protected]>.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
<http://groups.google.com/group/rubyonrails-core?hl=en>.
--
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:rubyonrails-core%[email protected]>.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
<http://groups.google.com/group/rubyonrails-core?hl=en>.
--
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:[email protected]>.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
<http://groups.google.com/group/rubyonrails-core?hl=en>.
--
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:[email protected]>.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
<http://groups.google.com/group/rubyonrails-core?hl=en>.
--
You received this message because you are subscribed to the Google
Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/JUgMoRWK35sJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.