how to add custom methods to ActionController::Base, ActiveRecord::Base

I want to add custom methods to ActionController::Base,
ActiveRecord::Base so that everything that extends it will have access
to these methods in my Rails app. What is the best practice for doing
this? I know I can create a file in lib and require it all the time
but it seems like there should be a better way.

For example:

class ActionController::Base

def controller_path
   self.class.controller_path
end

end

class ActiveRecord::Base
def foo_id(prefix=nil)
   display_id = new_record? ? "new" : id
   prefix ||= self.class.name.underscore
   prefix != :bare ? "#{prefix.to_s}_#{display_id}" : display_id
end
end

Thanks,
Frank Kim