```ruby
require 'event_calendar'
require 'event_calendar/calendar_helper'
require 'rails'

module EventCalendar
  class Railtie < Rails::Engine
    initializer :after_initialize do
      ActionController::Base.helper EventCalendar::CalendarHelper
      ActiveRecord::Base.extend EventCalendar::ClassMethods
    end
  end
end
```

Make sure ActiveRecord::Base is defined before attempting to extend.
user
```ruby
require 'event_calendar'
require 'event_calendar/calendar_helper'
require 'rails'

module EventCalendar
  class Railtie < Rails::Engine
    initializer :after_initialize do
      if defined?(ActionController::Base)
        ActionController::Base.helper EventCalendar::CalendarHelper
      end
      if defined?(ActiveRecord::Base)
        ActiveRecord::Base.extend EventCalendar::ClassMethods
      end
    end
  end
end
```
assistant