有人可以就以下 CSV 解析问题提出建议:
CSV:
Robert,Lobos,lobs@email.com
Klein,Kleinerer,kln@gmail.com
Gross,Grosserer,gr@grosserer.de
方法:
def upload
if (params[:contactList])
csv_content = params[:contactList].read
@recipients = {}
CSV.parse(csv_content) do |row|
@recipients[row[0]] = {'forename' => row[0], 'surname' => row[1], 'email' => row[2]}
end
render 'index'
end
end
目标是渲染模板中的值,如下所示:
<% @recipients.each do |recipient| %>
<option value="test"><%= recipient['forename'] %> <%= recipient['surname'] %> (<%= recipient['email'] %>)</option>
<% end %>
目前抛出:
无法将字符串转换为整数
实现上述目标的最佳方法/快速修复是什么?