Could someone advise with the following CSV parsing issue:
CSV:
Robert,Lobos,lobs@email.com
Klein,Kleinerer,kln@gmail.com
Gross,Grosserer,gr@grosserer.de
Method:
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
Target is to render the values in the template as following:
<% @recipients.each do |recipient| %>
<option value="test"><%= recipient['forename'] %> <%= recipient['surname'] %> (<%= recipient['email'] %>)</option>
<% end %>
Currently throws up with:
can’t convert String into Integer
What’s the best way/quickfix to achieve the above?
To iterate a hash with a block, the
keyandvalueof the hash entries are provided to the block.should be