For extending models (and controller methods) I use 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
Then you can let your user know to add an include
statement in the readme.
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
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
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.