Last active
November 18, 2015 02:51
-
-
Save huacnlee/8b3f03882ab196f2288c to your computer and use it in GitHub Desktop.
Extend Rails Application without change original files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializes/0_custom_extends.rb | |
# 让 Rails Autoload Path 载入 lib/custom 里面的内容 | |
# 让 lib/custom/uploaders 里面的东西优先级更高 | |
ActiveSupport::Dependencies.autoload_paths.delete("#{Rails.root}/app/uploaders") | |
ActiveSupport::Dependencies.autoload_paths.delete("#{Rails.root}/app/models") | |
ActiveSupport::Dependencies.autoload_paths += %W( | |
#{Rails.root}/lib/custom/models | |
#{Rails.root}/lib/custom/models/hooks | |
#{Rails.root}/lib/custom/models/concerns | |
#{Rails.root}/app/models | |
#{Rails.root}/lib/custom/controllers | |
#{Rails.root}/lib/custom/controllers/concerns | |
#{Rails.root}/lib/custom/services | |
#{Rails.root}/lib/custom/workers | |
#{Rails.root}/lib/custom/uploaders | |
#{Rails.root}/lib/custom/helpers | |
#{Rails.root}/lib/custom | |
#{Rails.root}/app/uploaders | |
) | |
# === Extend Routes === | |
# Prepend routes, add more route | |
Rails.application.routes.prepend do | |
get 'foo' => "you_new_controller#foo" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/custom/models/user.rb | |
require_dependency Rails.root.join('app/models/user') | |
puts "==== Init Custom Features ===" | |
# === Extend Models === | |
User.send(:include, UserExt) | |
# === Controller === | |
ApplicationController.send(:include, ApplicationControllerExt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment