我有这样的工作:jobs / create_site_map.rb
class CreateSiteMap
@queue = :create_site_map
def self.perform(slct_common_path, http_host, domain_name)
... some code ...
q_jobs = TJob.q_job_site_map(m_site.id)
q_jobs.each do |job|
site_map_content =
"\n\t\t<url>
\t\t<loc>#{site_frontsiteurl}index.cfm?fuseaction=job.detail&sgtno=#{job.shigoto_no}</loc>
\t\t<lastmod>#{job.job_dt.strftime("%F")}</lastmod>
\t\t<changefreq>daily</changefreq>
\t\t<priority>0.8</priority>
\t\t</url>\n"
sitemap_data << site_map_content
end
end
end
我想将上面的“ site_map_content”变量带到一个.xml文件(模板)中,以便多次重用,例如:
<url>
<loc>#{site_frontsiteurl}index.cfm?fuseaction=job.detail&sgtno=#{job.shigoto_no}</loc>
<lastmod>#{job.job_dt.strftime("%F")}</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
但是如何将参数传递到xl文件中?请帮助我。
template = Erb.new(File.read('file_path'))#这是一个yml文件
然后将数据传递到模板中:struct = OpenStruct.new(data)
YAML.load template.result(
struct.instance_eval { binding }
)
稍后您可以将yml转换为xml。