Created
May 11, 2016 07:56
-
-
Save rottame/be6d673d61db68e2febe55bb8a5a4408 to your computer and use it in GitHub Desktop.
rails subsite
This file contains hidden or 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
def config_site(site) | |
paths = Rails::Paths::Root.new(Rails.root.join("site_#{site}")) | |
paths.add "app", eager_load: true, glob: "*" | |
paths.add "app/assets", glob: "*" | |
paths.add "app/controllers", eager_load: true | |
paths.add "app/helpers", eager_load: true | |
paths.add "app/models", eager_load: true | |
paths.add "app/mailers", eager_load: true | |
paths.add "app/views" | |
paths.add "app/controllers/concerns", eager_load: true | |
paths.add "app/models/concerns", eager_load: true | |
paths.add "config/locales", glob: "*.{rb,yml}" | |
ActionController::Base.class_eval do | |
self.prepend_view_path paths["app/views"] | |
end | |
ActionMailer::Base.class_eval do | |
self.prepend_view_path paths["app/views"] | |
end | |
ActiveSupport::Dependencies.autoload_paths.unshift(*(paths.autoload_paths + paths.eager_load + paths.autoload_once).uniq) | |
ActiveSupport::Dependencies.autoload_once_paths.unshift(*paths.autoload_once) | |
Rails.application.config.i18n.railties_load_path.concat(paths["config/locales"].existent) | |
Rails.application.config.assets.paths.unshift(*paths["app/assets"].existent_directories) | |
Rails.application.config.assets.precompile += [ | |
Proc.new { |path, fn| | |
fn =~ /site_#{site}\/app\/assets/ && !%w(.js .css).include?(File.extname(path)) | |
}, | |
/(?:\/|\\|\A)application\.(css|js)$/ | |
] | |
end | |
in Rails project | |
/site_xyz/app/[assets|controllers|models|helpers|views] | |
/site_xyz/config/locales | |
in an initializer | |
config_site('xyz') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment