Skip to content

Instantly share code, notes, and snippets.

@tcmacdonald
Created June 27, 2011 13:54
Show Gist options
  • Save tcmacdonald/1048895 to your computer and use it in GitHub Desktop.
Save tcmacdonald/1048895 to your computer and use it in GitHub Desktop.
Loading an Engine's Classes First in Rails
# make sure engine classes load first.
# @see http://stackoverflow.com/questions/5045068/extending-controllers-of-a-rails-3-engine-in-the-main-app/5100825
require 'active_support/dependencies'
module ActiveSupport::Dependencies
alias_method :require_or_load_without_multiple, :require_or_load
def require_or_load(file_name, const_path = nil)
if file_name.starts_with?(Rails.root.to_s + '/app')
relative_name = file_name.gsub(Rails.root.to_s, '')
@engine_paths ||= CologyCom::Application.railties.engines.collect{|engine| engine.config.root.to_s }
@engine_paths.each do |path|
engine_file = File.join(path, relative_name)
require_or_load_without_multiple(engine_file, const_path) if File.file?(engine_file)
end
end
require_or_load_without_multiple(file_name, const_path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment