module EducodeSales module ApplicationHelper def current?(css, path) if path.is_a?(Array) ? (current_page?(path.first) || request.path == path.last) : current_page?(path) css else ' ' end end def url_to_avatar(source) return "" if source.blank? if File.exist?(disk_filename(source&.class, source&.id)) && File.file?(disk_filename(source&.class, source&.id)) ctime = File.ctime(disk_filename(source&.class, source&.id)).to_i if source.class.to_s == 'User' File.join(relative_path, ["#{source&.class}", "#{source&.id}"]) + "?t=#{ctime}" else File.join("images/avatars", ["#{source&.class}", "#{source&.id}"]) + "?t=#{ctime}" end elsif source.class.to_s == 'User' str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g" File.join(relative_path, "#{source.class}", str) elsif source.class.to_s == 'Subject' File.join("images","educoder", "index", "subject", "subject#{rand(19)}.jpg") elsif source.class.to_s == 'Shixun' File.join("images","educoder", "index", "shixun", "shixun#{rand(23)}.jpg") end end def disk_filename(source_type,source_id,image_file=nil) File.join(storage_path, "#{source_type}", "#{source_id}") end def storage_path File.join(Rails.root, "public", "images", relative_path) end def relative_path "avatars" end def base_url url = Rails.application.config_for(:configuration)['wechat_pay']['callback_url'] if url.include?("https://data.educoder") "https://www.educoder.net" elsif url.include?("'https://pre-data.educoder") "https://pre.educoder.net" else "https://test.educoder.net" end end end end