Hi Seth,

I would almost certainly recommend against your approach :S By placing
application.rb within your engine, you are locking it away from the
user, and therefore preventing them from adding any of their own logic
to the ApplicationController class. If the user tries to create their
own 'application.rb' file in /app/controllers, your engine file will
no longer be loaded.

Current 'best practice' would be to wrap your methods in a module and
either have the user include this module in their
ApplicationController class, or automatically include it in
ActionController::Base by sending an :include message in your
init_engine.rb (you can't reliably send the include to
ApplicationController because this class gets reloaded in development
mode, whilst init_engine.rb files are only evaluated at startup).

For your particular engine, you could replace your application.rb with
this module:

  module SubstructApplicationController
    include Substruct
    include LoginSystem

    def self.included(base)
      base.class_eval do
        model :user
        model :cart
        model :order_line_item
        model :order_shipping_type

        def cache
          $cache ||= SimpleCache.new 1.hour
        end
      end
    end
  end

... and then have the user include that in their own
ApplicationController (bear in mind that is untested code, I'm just
writing it from memory of how these things should work).

HTH,

- james

On 3/23/06, Seth <[EMAIL PROTECTED]> wrote:
> James - for my Substruct product I'm just shoving application.rb and
> application_helper.rb in my engine itself - and having people delete
> those files in their /app directory.
>
> Is this bad practice? Can you check out my engine and let me know if I
> should be doing it differently?
>
> http://dev.subimage.com/projects/substruct/wiki/InstallingSubstruct
> http://www.subimage.com/files/substruct-0.054.tar.gz
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> engine-developers mailing list
> [email protected]
> http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org
>


--
* J *
  ~
_______________________________________________
engine-developers mailing list
[email protected]
http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org

Reply via email to