From 8e75b19dd5d84699f4adf74bb582796325b2be3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Sun, 21 Jul 2024 15:22:24 +0800 Subject: [PATCH] Fix host url. --- app/controllers/universal_tables_controller.rb | 6 +++++- lib/tasks/universal_table_tasks.rake | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/universal_tables_controller.rb b/app/controllers/universal_tables_controller.rb index 6daa4eb..2be32dc 100644 --- a/app/controllers/universal_tables_controller.rb +++ b/app/controllers/universal_tables_controller.rb @@ -144,6 +144,10 @@ class UniversalTablesController < ApplicationController table = UTable.where(:category_id => params[:cat]).first rescue nil page = Page.where(:page_id => params[:page_id]).first if !table.nil? + host_url = Site.first.root_url + if host_url == "http://" + host_url = request.protocol + request.host_with_port + end @rows = [] @tablecolumns = table.table_columns.where(:display_in_index => true).asc(:order) entries = get_entries(params, table, page, false) @@ -167,7 +171,7 @@ class UniversalTablesController < ApplicationController text = format_date(ce.period_from, column.date_format) + " ~ " + format_date(ce.period_to, column.date_format) text = "" if text.starts_with?(" ~") when "image" - text = "http://#{request.host_with_port}" + ce.image.thumb.url + text = host_url + ce.image.thumb.url end cols << {"text" => text} else diff --git a/lib/tasks/universal_table_tasks.rake b/lib/tasks/universal_table_tasks.rake index 64f7123..7eb7454 100644 --- a/lib/tasks/universal_table_tasks.rake +++ b/lib/tasks/universal_table_tasks.rake @@ -8,8 +8,11 @@ namespace :universal_table_tasks do I18n.locale = :zh_tw table = UTable.find(id) ac = ActionController::Base.new() - url = "http://#{args.url}" - xlsx = ac.render_to_string handlers: [:axlsx], formats: [:xlsx], template: "utable_export/export", locals: {table: table, site_in_use_locales: Site.first.in_use_locales, url: url} + host_url = Site.first.root_url + if host_url == "http://" + host_url = "http://#{args.url}" + end + xlsx = ac.render_to_string handlers: [:axlsx], formats: [:xlsx], template: "utable_export/export", locals: {table: table, site_in_use_locales: Site.first.in_use_locales, url: host_url} dirname = "public/uploads/utable_export/#{id}" FileUtils.mkdir_p(dirname) unless File.exist?(dirname) f = "#{dirname}/#{table.title.gsub(/[ "'*@#$%^&()+=;:.,?>|\\\/<~_!:,、。!?;「」〈〉【】/]/,'')}.xlsx"