I have an RoR app running on Heroku, where I'm using the Cloudmailin add-on to send e-mails into the app itself.
The content of these e-mails will be used to create new content in the Database. It's an app, where the users can place Bets against other users. The results are the e-mailed into the app, so a settlement process can be triggered.
I have an Incoming Mails Controller that looks like this:
class IncomingMailsController < ApplicationController
skip_before_filter :verify_authenticity_token
def create
Spotprice.create(:deliverydate => Date.tomorrow, :spotarea_id => Spotarea.find_by_areaname("Phelix").id, :product_id => Product.find_by_productname("Base").id, :value_in_currency => "87")
end
end
The above works just fine, but I need it to read the content of the e-mail instead of the static content in the code above (Phelix, Base, Date.tomorrow and 87).
So how do I do that when the e-mail body looks like the below:
23112012 Phelix Base 87.00
23112012 System Peak 64.55
The mail has multiple lines, where each line is one new Spotprice in the Database. This means that I somehow also have to loop throught each line in tha mail and create each Spotprice seperatly.
Help will be very much appriciated :)
If all you're looking for is how to parse each line of space delimited text, this should work -
and email_text_array will look like