Hi, I’m writing an application that generate some sort of prepaid cards, each card with a PIN and a serial number. All serials and PINs are being hashed when saved to the database. For more security, I need the generated numbers to be sent via email to the Admin when they generated, there is no way for the admin to view the numbers from inside the application. The process is as the following: Admin chooses to generate 1000 new cards (for example) → Numbers are sent to the Admin by email before they get hashed → numbers are hashed and saved to the database.
The above scenario works for me without problems, right now the generated numbers are being sent as plain text in the body of the email message, my question is that good for large amount of numbers (thousands of cards)? Or should I export them as a CSV file and send it as attachment? I checked FasterCSV and the standard Ruby CSV library but as I understand they wouldn’t work for huge amount of data. Should I consider exporting to Excel file? Or do you think that it’s just fine to send them in the body of the email message? Or do you suggest some alternative way that I didn’t think about?
For reference: this is the generate method in the controller:
def generate @cards = {} params[:card][:number_of_cards].to_i.times do pin = rand(999999999999).to_s.center(12, rand(9).to_s) serial = rand(999999999999).to_s.center(12, rand(9).to_s) @cards[serial] = pin Card.create({:pin => pin, :serial => serial}) end PostOffice.deliver_send_cards(@cards) redirect_to(cards_path) end
In the model:
def before_save self.pin = Card.encrypt(pin) self.serial = Card.encrypt(serial) end
In the Action Mailder:
def send_cards(cards)
@recipients = "someemail@gmail.com"
@from = "someaddress"
headers "Reply-to" => "someemail@gmail.com"
@subject = "New generated cards"
@sent_on = Time.now
body[:cards] = cards
end
send_cards.html.erb:
<%@cards.each do |a,b| %> <%= a +“,”+ b %> <%end%>
Thanks in advance