Rails.application.routes.draw do if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console') Thread.new do if AlbumSetting.count == 0 album_setting = AlbumSetting.create else album_settings = AlbumSetting.all.to_a album_setting = album_settings.first if album_settings.count > 1 album_settings[1..-1].each do |album_setting| album_setting.destroy end end end s = Site.first update_flag = s.respond_to?(:tmp_flags) need_update = !update_flag || !(s.tmp_flags.include?('ga1')) if need_update albums1 = Album.where(:order.in => [nil,-1]).desc(:created_at) albums2 = Album.all.where(:order.ne=>-1).and(:order.ne=>nil).asc(:order) fiter_albums = albums1.concat(albums2) fiter_albums.each_with_index do |album, i| album.order = i album.min_order = -1 album.save images1 = album.album_images.where(:order.in => [nil,-1]).desc(:created_at).to_a images2 = album.album_images.where(:order.gt => -1).asc(:order).to_a images = images1.concat(images2) images.each_with_index do |image, j| image.order = i image.save end end AlbumSetting.update_all(:min_order=>-1) if update_flag s = Site.first s.tmp_flags << 'ga1' s.save end puts "Gallery order fix!" end Album.create_indexes AlbumImage.create_indexes end end locales = Site.first.in_use_locales rescue I18n.available_locales scope "(:locale)", locale: Regexp.new(locales.join("|")) do get "/xhr/galleries/theater/:id" => "galleries#theater" namespace :admin do get "galleries/get_photoData_json" => "galleries#get_photoData_json" get "galleries/recreate_image" => "galleries#recreate_image" get "galleries/crop_process" => "images#crop_process" post "galleries/recreate_image/recreate_progress" => "galleries#recreate_progress" get "galleries/recreate_image/finish_recreate" => "galleries#finish_recreate" get "galleries/batch_crop" => "images#batch_crop" get "galleries/new_images" => "galleries#new_images" get "galleries/last_image_id" => "galleries#last_image_id" post "galleries/set_cover" => "galleries#set_cover" post "galleries/delete_photos" => "images#delete_photos" post "galleries/update_image" => "images#update_image" post "galleries/image_tagging" => "images#image_tagging" post "galleries/order" => "images#changeorder" post "galleries/translate" => "galleries#call_translate" post "galleries/save_crop" => "galleries#save_crop" get "galleries/rotate_images" => "galleries#rotate_images" get "galleries/upload_process" => "galleries#upload_process" post "galleries/start_upload_process" => "galleries#start_upload_process" post "galleries/init_upload" => "galleries#init_upload" post "galleries/get_tag" => "galleries#get_tag" post "galleries/update_album_setting" => "galleries#update_album_setting" get "galleries/setting" => "galleries#setting" resources :galleries do get "imgs" => "galleries#imgs" member do get "import" get "excel_format" post "importimages" end collection do post 'select_albums' end end resources :images post "galleries/upload_image" => "galleries#upload_image" # match "image_tagging" => "album_images#image_tagging" end end end