Fix host url.

This commit is contained in:
邱博亞 2024-07-21 15:22:24 +08:00
parent 179646fcfa
commit 8e75b19dd5
2 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -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"