【发布时间】:2016-05-23 23:23:40
【问题描述】:
我想在我的电子邮件中附加一个动态文件。我有以下代码:
attachments["#{@company}likelist.xls"] = File.read("#{Rails.root}/app/views/products/like_list.xls.erb")
like_list.xls.erb 是通过在 Ruby 中迭代变量创建的动态 HTML 表。我使用respond_to format.xls 将like_list.html.erb 表转换为XLS,但是,发送的附件是空的,因为没有执行任何Ruby 代码。 File.read 只读取静态文件。
like_list.xls.erb 看起来像这样:
<table border="1">
<thead>
<tr>
<th><%= t ('product_table.name')%></th>
<th><%= t ('product_table.code')%></th>
</tr>
</thead>
<tbody>
<% @like_list.each do |key, value| %>
<% value.each do |t| %>
<tr>
<td><%=t.code%></td>
<td><%=key%></td>
...
有什么方法可以在 Rails 4 中附加动态文件?
【问题讨论】:
标签: ruby-on-rails ruby