prevent error after bundle update without upgrade kernel

This commit is contained in:
邱博亞 2021-11-21 10:52:37 +08:00
parent 0f60e393ca
commit c11bc42440
7 changed files with 346 additions and 84 deletions

View File

@ -173,8 +173,11 @@ if bundle_update_flag
end
Bundler.with_clean_env{%x[cp -f '#{env_pwd}'/Gemfile '#{env_pwd}'/Gemfile.bak123]}
Bundler.with_clean_env{%x[cp -f '#{app_path}'/temp_file/Gemfile '#{env_pwd}'/Gemfile]}
#command4 = ";cp -rf #{app_path}/temp_file/app #{env_pwd}"
command4 = ""
if system("cd #{env_pwd} && git branch --contains '2f23511469505bd114df2c863a477a8730bcdefa'") #update mongoid version
command4 = ""
else
command4 = ";cp -rf #{app_path}/temp_file/app #{env_pwd};cp -rf #{app_path}/temp_file/config #{env_pwd}"
end
log_development = File.mtime(env_pwd+'/log/development.log').strftime('%Y%m%d%H%M').to_i rescue 0
log_production = File.mtime(env_pwd+'/log/production.log').strftime('%Y%m%d%H%M').to_i rescue 0
if log_development > log_production

View File

@ -130,20 +130,20 @@ class Admin::PlaygroundController < OrbitAdminController
Bundler.with_clean_env do
IO.popen(command,:err=>[:child, :out]) do |stdout|
stdout.each do |line|
l = line.chomp
mul.status['output'] << l
if l == "rake aborted!"
mul.status['error'] = true
end
mul.save
end
l = line.chomp
mul.status['output'] << l
if l == "rake aborted!"
mul.status['error'] = true
end
mul.save
end
end
mul.status['alive'] = false
mul.save
if command == 'bundle update'
system('sleep 2')
Bundler.with_clean_env{system("kill -s USR2 `cat tmp/pids/unicorn.pid`")}
end
mul.status['alive'] = false
mul.save
if command == 'bundle update'
system('sleep 2')
Bundler.with_clean_env{system("#{RESTART_CMD}")}
end
end
rescue => e
mul.status['alive'] = false
@ -160,7 +160,7 @@ class Admin::PlaygroundController < OrbitAdminController
end
def restart_server
cmd ="kill -s USR2 `cat tmp/pids/unicorn.pid`"
cmd ="#{RESTART_CMD}"
exec_other_command(cmd)
end
@ -172,7 +172,7 @@ class Admin::PlaygroundController < OrbitAdminController
def restart_unicorn(mode)
mode = Rails.env if mode.nil?
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
content = "kill -s TERM `cat tmp/pids/unicorn.pid` && unset UNICORN_FD && sleep 1 && bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode} | at now"
content = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s TERM $UNICORN_PID ; while (kill -0 $UNICORN_PID > /dev/null 2>&1) ; do printf '.' && sleep 1 ; done ; unset UNICORN_FD; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{mode}"
Thread.new do
Bundler.with_clean_env{system(content)}
end

View File

@ -1,17 +1,47 @@
class Admin::SitesController < OrbitAdminController
before_filter :get_site
before_filter :set_git_branch, :only=>[:check_updates, :update_orbit]
before_action :create_page_set
def create_page_set
@site = @current_site.nil? ? Site.first : @current_site
if( @site.page_sets.count==0 rescue false)
@site.page_sets.create()
elsif @site.page_sets.count>1
@site.page_sets.each_with_index do |i,v|
if i!=0
v.delete
include Admin::GmailHelper
helper_method :GeneratePermissionUrl
def get_all_databases
nginx_exe = %x[ps -o args -C nginx| grep 'daemon'| awk '{print $4}'].split("\n")[0]
if nginx_exe.nil?
render :json => {}
else
nginx_config = %x[#{nginx_exe} -V 2>&1 | grep -o '\\-\\-conf-path=\\(.*conf\\)' | cut -d '=' -f2].sub("\n",'')
include_paths = `grep include #{nginx_config}`.split("\n").map{|s| s.strip.split("#").first.match(/include\s+([^;]*)/)[1]}
include_paths = include_paths.select{|path| path.match(/(modules-enabled|mime\.types|conf\.d|sites-enabled)/).nil? }
database_info = {}
include_paths.each do |include_path|
root_paths = `grep root #{include_path}`.split("\n").map{|s| s.strip.split("#").first.match(/root\s+([^;]*)/)[1]}
root_paths = root_paths.map{|path| File.dirname(path)}
root_paths.each do |root_path|
mongoid_config = YAML.load(File.read("#{root_path}/config/mongoid.yml")) rescue nil
db = mongoid_config["development"]["sessions"]["default"]["database"] rescue nil
if db.present?
db = db.to_s
site_nginx_config = `grep -H #{root_path} #{include_path}`.split(':')[0] rescue ""
if site_nginx_config.present?
server_names = `grep server_name #{site_nginx_config}`.split("\n").map{|s| s.split('#').first.match(/server_name\s+([^;]*)/)[1].split(/\s/) rescue nil}
server_names = server_names.flatten.compact
server_names = server_names.select{|s| ip_match = s.match(/[\d\.]+/);ip_match.nil? ? true : (ip_match[0] != s)}
if server_names.count != 0
ports = `grep listen #{site_nginx_config}`.split("\n").map{|s| s.split('#').first.match(/\d+/)[0] rescue nil}.compact
if ports.include? "443"
database_info[db] = "https://#{server_names[0]}"
else
port = ports[0]
if port
database_info[db] = "http://#{server_names[0]}#{port == "80" ? '' : ":#{port}"}"
end
end
end
end
end
end
end
end
@site.update(:database_info=>database_info)
render :json => database_info
end
end
layout "structure"
@ -30,7 +60,7 @@ class Admin::SitesController < OrbitAdminController
response.body = {'success'=>true}.to_json
end
data = JSON.parse(response.body)
%x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
%x(#{RESTART_CMD})
sleep 5
end
def index
@ -113,6 +143,14 @@ class Admin::SitesController < OrbitAdminController
end
def preference
@member_extra_db = File.read("config/member_extra_db.txt").strip rescue ""
if @member_extra_db.blank?
@member_extra_db = @site.member_extra_db
else
@site.update(:member_extra_db=>@member_extra_db)
end
@current_database = Site.collection.database.name
@database_info = @site.database_info.except(@current_database) rescue {}
end
def update_orbit
@ -130,14 +168,16 @@ class Admin::SitesController < OrbitAdminController
Site.update_all({:enable_language_detection => false})
end
end
if !@site.in_use_locales.include?I18n.locale
if !@site.in_use_locales.include? I18n.locale
I18n.locale = @site.in_use_locales.first
redirect_to admin_site_preference_path(current_site)
else
redirect_to :back
end
%x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
sleep 5
Thread.new do
sleep 1
%x(#{RESTART_CMD})
end
end
def update_manager
@ -181,7 +221,7 @@ class Admin::SitesController < OrbitAdminController
git_add_except_public = Dir['*'].select{|v| v!= 'public' && v!= 'log' && v != 'dump' && v != 'tmp'}.collect do |v|
"#{git} add -f --all --ignore-errors '#{v}'"
end.join(' ; ')
git_add_custom = (Dir['*'].select{|v| v !='app' && v != 'lib' && v != 'config' && v != 'public' && v!= 'log' && v != 'dump' && v != 'tmp'} + ['app/templates','config/mongoid.yml','config/extra_lang.txt']).collect do |v|
git_add_custom = (Dir['*'].select{|v| v !="config.ru" && v !='app' && v != 'lib' && v != 'config' && v != 'public' && v!= 'log' && v != 'dump' && v != 'tmp'} + ['app/templates','config/mongoid.yml','config/extra_lang.txt']).collect do |v|
"#{git} add -f --all --ignore-errors '#{v}'"
end.join(' ; ')
git_restore = "#{git} checkout ."
@ -192,7 +232,9 @@ class Admin::SitesController < OrbitAdminController
if %x[#{git} config user.email].empty?
%x[#{git} config --global user.email "orbit@rulingcom.com"]
end
Bundler.with_clean_env{system("#{git_add_except_public} ; #{git} commit -m auto_backup_before_#{type}_#{time_now} --allow-empty && #{git} reset #{commit} --mixed ; #{git_add_custom} ; #{git_restore} ; #{git_add_except_public} ; #{git} commit -m complete_#{type}_#{time_now} --allow-empty")}
site = Site.first
Bundler.with_clean_env{system("#{git_add_except_public} ; #{git} commit -m auto_backup_before_#{type}_#{time_now} --allow-empty && #{git} reset #{commit} --mixed ; #{git_add_custom} ; #{git_restore} ; #{git_add_except_public} ; #{git} clean -f -- app/models ; #{git} commit -m complete_#{type}_#{time_now} --allow-empty")}
site.update_attributes(update_flag: true) rescue nil
mul.update_attributes(status: 'finish')
end
end
@ -215,7 +257,7 @@ class Admin::SitesController < OrbitAdminController
def bundle_install
Bundler.with_clean_env { system("cd #{Rails.root} && bundle update") }
%x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
%x(#{RESTART_CMD})
sleep 2
render :nothing => true
end
@ -224,7 +266,7 @@ class Admin::SitesController < OrbitAdminController
mode = Rails.env
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
render :nothing => true
Bundler.with_clean_env{system("kill -s TERM `cat tmp/pids/unicorn.pid` && unset UNICORN_FD && sleep 1 && bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}")}
Bundler.with_clean_env{system("UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s TERM $UNICORN_PID ; while (kill -0 $UNICORN_PID > /dev/null 2>&1) ; do printf '.' && sleep 1 ; done ; unset UNICORN_FD; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{mode}")}
end
private
@ -244,21 +286,21 @@ class Admin::SitesController < OrbitAdminController
# Site.update_all({:default_locale => nil})
# end
unless params[:site][:in_use_locales].nil?
in_user_locales = []
I18n.available_locales.each do |locale|
in_user_locales << locale if params[:site][:in_use_locales][locale].eql?("1")
unless params[:site][:in_use_locales].nil?
in_user_locales = []
I18n.available_locales.each do |locale|
in_user_locales << locale if params[:site][:in_use_locales][locale].eql?("1")
end
params[:site][:in_use_locales] = in_user_locales
end
params[:site][:in_use_locales] = in_user_locales
end
if params[:site][:phone_number].nil?
params[:site][:phone_number] = []
# else
# params[:site][:phone_number] = params[:site][:phone_number]
end
params[:site][:sign_up_roles] = [] if !params[:site][:sign_up_roles].present?
params.require(:site).permit!
if params[:site][:phone_number].nil?
params[:site][:phone_number] = []
# else
# params[:site][:phone_number] = params[:site][:phone_number]
end
params[:site][:sign_up_roles] = [] if !params[:site][:sign_up_roles].present?
params.require(:site).permit!
end

View File

@ -5,17 +5,16 @@ module OrbitBackendHelper
ActionView::Helpers::FormBuilder.send(:include,OrbitFormHelper)
end
def group_impression_by_day(field,day_limit,start_day=Date.today,format = 'day')
limit_ele = Impression.desc(:id).where({ created_at: { "$lt" => start_day-(day_limit-2).days }}).first || Impression.first
def group_impression_by_day(field,day_limit,start_day=Time.now,format = 'day')
key_op = [['year','$year'],['month', '$month'], ['day', '$dayOfMonth']]
key_op = key_op.take(1 + key_op.find_index { |key, op| format == key })
project_date_fields = Hash[*key_op.collect { |key, op| [key, {op => "$#{field}"}] }.flatten]
group_id_fields = Hash[*key_op.collect { |key, op| [key, "$#{key}"] }.flatten]
pipeline = [
{"$match"=> {"_id" => {"$gte" => (limit_ele['_id'] rescue '')}}},
{"$match"=> {"created_at" => {"$gte" => (start_day.to_date-(day_limit-2).days rescue ''), "$lte" => start_day}}},
{"$project" => {field => 1}.merge(project_date_fields)},
{"$group" => {"_id" => group_id_fields,"count" => {"$sum" => 1}}},
{"$sort" => {"_id"=>-1}}
{"$sort" => {"created_at"=>-1}}
]
tmp = Impression.collection.aggregate(pipeline)
if tmp.count < day_limit
@ -140,7 +139,7 @@ module OrbitBackendHelper
elsif obj.class == Page && current_user.is_manager?(ModuleApp.where(:key=>'page_content').first)
return true
elsif @current_user_is_sub_manager && !create_user.nil?
create_user == current_user.id.to_s
return ( @user_authenticated_categories.include?(obj.category_id) rescue (create_user == current_user.id.to_s))
else
@user_authenticated_categories.include?obj.category_id rescue (current_user.is_manager?(@module_app) rescue false)
end
@ -165,7 +164,7 @@ module OrbitBackendHelper
params_to_send = {'store_token' => current_site.store_token}
uri = URI.parse(OrbitStore::URL)
http = Net::HTTP.new(uri.host,uri.port)
http.read_timeout = 25 #seconds
http.read_timeout =1 #seconds
request = Net::HTTP::Get.new("/site/permissions")
request.body = params_to_send.to_query
http.open_timeout = 1 #set read_timeout to 1 second to avoid web die caused by no response

View File

@ -68,10 +68,18 @@ module OrbitFormHelper
concat text_field_tag nil,options[:value], :placeholder => options[:placeholder], :class => options[:input_class], 'data-format' => options[:format], :data => options[:data]
end
else
if !options['id'].nil?
concat text_field object_name , :placeholder => options[:placeholder], :class => options[:input_class], 'data-format' => options[:format], :value => options[:value], :data => options[:data], :id => options['id']
if !@object.nil?
if !options['id'].nil?
concat text_field object_name , :placeholder => options[:placeholder], :class => options[:input_class], 'data-format' => options[:format], :value => options[:value], :data => options[:data], :id => options['id']
else
concat text_field object_name, :placeholder => options[:placeholder], :class => options[:input_class], 'data-format' => options[:format], :value => options[:value], :data => options[:data]
end
else
concat text_field object_name, :placeholder => options[:placeholder], :class => options[:input_class], 'data-format' => options[:format], :value => options[:value], :data => options[:data]
if !options['id'].nil?
concat text_field_tag object_name ,options[:value], :placeholder => options[:placeholder], :class => options[:input_class], 'data-format' => options[:format], :value => options[:value], :data => options[:data], :id => options['id']
else
concat text_field_tag object_name ,options[:value], :placeholder => options[:placeholder], :class => options[:input_class], 'data-format' => options[:format], :value => options[:value], :data => options[:data]
end
end
end
concat (content_tag :span, :class => 'add-on clearDate' do

View File

@ -6,6 +6,26 @@ class Site
DEBUG = false
has_many :page_sets, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :page_sets, :allow_destroy => true
def popup_subparts
part = SitePagePart.first
part.sub_parts(true)
end
field :password_failed_lock_num, type: Integer, default: 5
field :password_failed_lock_time, type: Integer, default: 1
field :password_change_constrained, type: Integer, default: 0
field :social_share_hide_in_menu, type: Boolean, default: false
field :social_share_position, type: Integer, default: 0
field :render_popup_only_on_root, type: Boolean, default: false
field :orbit_bar_extra_render_files_inside, type: Array, default: []
field :orbit_bar_extra_render_files_outside, type: Array, default: []
field :display_default_accesskey_help_in_sitemap, type: Boolean, default: false
field :accessibility_mode, type: Boolean, default: false
field :redirect_404_to_home, type: Boolean, default: false
field :block_cross_site_request, type: Boolean, default: false
field :member_extra_db, type: String, :default => ""
field :member_extra_url, type: String, :default => ""
field :database_info, type: Hash, :default => {}
field :root_url, type: String
field :update_flag, type: Boolean, default: true
field :password_high_security, type: Boolean, default: false
@ -17,6 +37,7 @@ class Site
field :address, type: String
field :footer, localize: true
field :social_share, type: String
field :floating_window, type: Boolean, default: false
field :sub_menu, localize: true
field :site_type
field :site_map_link, type: String, :default => "/sitemap"
@ -48,6 +69,7 @@ class Site
field :store_token
field :enable_last_update, type: Boolean, :default => false
field :personal_plugins_sort, type: Array, :default => []
field :personal_plugins_custom_names, type: Hash, :default => {}
field :sign_up_roles, type: Array, :default => []
field :required_sign_up_attributes , :type => Hash , :default => {}
field :mobile_orbit_bar_title, localize: true
@ -86,43 +108,48 @@ class Site
field :login_text , type: String, :default => "", localize: true
field :sign_up_hint ,:type => Hash, :default => {}
field :sign_up_hint_enable ,:type => Hash, :default => {}
field :cache_menu_data , :type => String, :default => "", :localize => true
field :cache_header_data , :type => String, :default => "", :localize => true
field :mobile_cache_menu_data , :type => String, :default => "", :localize => true
field :mobile_cache_header_data , :type => String, :default => "", :localize => true
field :need_update_header_cache , :type => Boolean, :default => true, localize: true
field :need_update_mobile_header_cache , :type => Boolean, :default => true, localize: true
field :need_update_menu_cache , :type => Boolean, :default => true, localize: true
field :need_update_mobile_menu_cache , :type => Boolean, :default => true, localize: true
field :has_sub_home , :type => Boolean, :default => false
field :prohibit_general_memebers_access_backend_member_page , :type => Boolean, :default => false
mount_uploader :default_image, ImageUploader
mount_uploader :site_logo, ImageUploader
mount_uploader :site_logo_1, ImageUploader
mount_uploader :favicon, ImageUploader
mount_uploader :mobile_icon, ImageUploader
before_save do
begin
cache_header(false)
rescue => e
File.open("test.html","w+"){|f| f.write(e.backtrace.join(""))}
puts "cache header failed"
end
end
after_save do
File.open("config/member_extra_db.txt","w+"){|f| f.write(self.member_extra_db)}
end
after_initialize do |record|
if !record.new_record?
if record.is_hidden_orbit_bar.nil?
record.is_hidden_orbit_bar = false
record.save
if !record.new_record? && !@skip_callback
save_flag = false
if record.orbit_bar_background_color == '#000000' && record.orbit_bar_text_color == '#000000'
record.orbit_bar_text_color = "#ffffff"
save_flag = true
end
if record.orbit_bar_background_color.nil?
record.orbit_bar_background_color = ""
record.save
if record.orbit_bar_submenu_background_color == '#000000' && record.orbit_bar_submenu_text_color == '#000000'
record.orbit_bar_submenu_text_color = "#ffffff"
save_flag = true
end
if record.orbit_bar_text_color.nil?
record.orbit_bar_text_color = ""
if save_flag
@skip_callback = true
record.save
@skip_callback = false
end
if record.orbit_bar_submenu_background_color.nil?
record.orbit_bar_submenu_background_color = ""
record.save
end
if record.orbit_bar_submenu_text_color.nil?
record.orbit_bar_submenu_text_color = ""
record.save
end
if record.orbit_bar_animation_time.nil?
record.orbit_bar_animation_time = "0.3s"
record.save
end
end
if record.orbit_bar_background_color == '#000000' && record.orbit_bar_text_color == '#000000'
record.update(:orbit_bar_text_color => '#ffffff')
end
if record.orbit_bar_submenu_background_color == '#000000' && record.orbit_bar_submenu_text_color == '#000000'
record.update(:orbit_bar_submenu_text_color => '#ffffff')
end
end
def register_site(url,university,department,email,country)
@ -131,4 +158,84 @@ class Site
store = Store.new(self.id.to_s,self.site_token,api_key)
store.post_client(self.id.to_s,self.site_token,self.title,url,university,department,email,country)
end
def cache_header(save_flag=true)
if defined?(Page)
org_mobile = $mobile
@site = self
self.in_use_locales.each do |locale|
I18n.with_locale(locale) do
[true,false].each do |mobile|
$mobile = mobile
self.store_cache_header_data($mobile,ApplicationHelper.render_header_for_extend(true))
end
end
end
$mobile = org_mobile
self.save if save_flag
end
end
def self.make_cache
@@ac_controller ||= ApplicationController.new
s = Site.first
@@ac_controller.class_eval{include ApplicationHelper}
@@ac_controller.instance_eval{@site = s;@key = s.template}
s.in_use_locales.each do |locale|
I18n.with_locale(locale) do
@@ac_controller.send("render_menu",false)
@@ac_controller.send("render_menu",true)
end
end
end
def get_cache_menu_data(is_mobile)
if is_mobile
if self.need_update_mobile_menu_cache
return nil
else
return self.mobile_cache_menu_data
end
else
if self.need_update_menu_cache
return nil
else
return self.cache_menu_data
end
end
end
def store_cache_menu_data(is_mobile,data)
if is_mobile
self.mobile_cache_menu_data = data
self.need_update_mobile_menu_cache = false
else
self.cache_menu_data = data
self.need_update_menu_cache = false
end
end
def get_cache_header_data(is_mobile)
if is_mobile
if self.need_update_mobile_header_cache
return nil
else
return self.mobile_cache_header_data
end
else
if self.need_update_header_cache
return nil
else
return self.cache_header_data
end
end
end
def store_cache_header_data(is_mobile,data)
if is_mobile
self.mobile_cache_header_data = data
self.need_update_mobile_header_cache = false
else
self.cache_header_data = data
self.need_update_header_cache = false
end
end
def reset_cache
localize_true = self.in_use_locales.map{|l| [l.to_s,true]}.to_h
self.class.all.update_all(:need_update_header_cache=>localize_true,:need_update_mobile_header_cache=>localize_true,:need_update_menu_cache=>localize_true,:need_update_mobile_menu_cache=>localize_true)
end
end

View File

@ -0,0 +1,103 @@
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
require "mongoid"
require "mongoid/railtie"
require "bson"
if Mongoid::VERSION.to_i < 5
require "moped"
Moped::BSON = BSON
else
Mongoid::Sessions = Mongoid::Clients
Mongoid::Clients::StorageOptions::ClassMethods.module_eval do
def store_in(options)
options[:client] = options.delete(:session) if options && options[:session]
Mongoid::Clients::Validators::Storage.validate(self, options)
storage_options.merge!(options)
end
end
end
module Mongoid
module Findable
def and_any_of(conditions)
self.or(conditions)
end
end
end
module Mongoid
class Criteria
def and_any_of(conditions)
if self.selector.count==0
tmp = self.or(conditions)
else
all_selector = self.selector
self.selector = {}
tmp = self.and([all_selector,{"$or"=>conditions}])
end
tmp
end
end
end
module ActionView::Helpers::AssetTagHelper
self.included do
def stylesheet_link_tag(*sources)
options = sources.extract_options!.stringify_keys
super(*sources,{media: :all}.merge(options))
end
end
end
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
dependency_gems = Gem::Specification.find_all.to_a.flat_map{|spec| spec.dependent_specs.map{|s| [s.name,s.version.to_s]}}.uniq.to_h
dependency_gems = dependency_gems.select{|gem,v| v=='0.0.1'}.keys
dependency_gems.each{|gem_name| Bundler.require.push(Bundler::Dependency.new(gem_name,:runtime))}
Bundler.require(:default, Rails.env)
module Orbit
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# tell the I18n library where to find your translations
I18n.load_path += Dir[Rails.root.join('lib', 'locale', '*.{rb,yml}')]
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')]
I18n.load_path += Gem::Specification.select{|v| v.source.class!=Bundler::Source::Rubygems}.map{|v| Dir[File.expand_path('../config/locales/*.yml',v.loaded_from)]}.flatten
# set default locale to something other than :en
config.i18n.enforce_available_locales = true
config.i18n.default_locale = :en
extra_lang = File.read('config/extra_lang.txt').scan(/.*extra_.*/).select{|v| v.exclude? '#'}[0].to_s.split(/extra_language.*:|,| /).select{|v| !v.empty?}.map{|v| v.to_sym} rescue []
all_locales = [:en, :zh_tw] + extra_lang
I18n.available_locales = config.i18n.available_locales = all_locales
require "i18n/backend/fallbacks"
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
fallbacks = {}
all_locales.each do |locale|
fallbacks[locale] = [locale,:en].uniq #all_locales.sort_by{|v| v == locale ? 0 : 1}
end
I18n.fallbacks = fallbacks
config.autoload_paths += %W(#{config.root}/lib)
#reload_gems = %w(impressionist) # names of gems which should autoreload
#config.autoload_paths += Gem.loaded_specs.values.inject([]){ |a,gem| a += gem.load_paths if reload_gems.include? gem.name; a }
#require 'active_support/dependencies'
#ActiveSupport::Dependencies.explicitly_unloadable_constants += reload_gems.map { |gem| gem.classify }
# config.paths["app/views"].unshift("#{Rails.root}/app/templates")
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
config.time_zone = 'Asia/Taipei'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# config.mongoid.observers = :orbit_observer
end
end