On Dec 1, 2014, at 6:12 AM, George Stoumpos <[email protected]> wrote:

> Hi there,
> 
> I am trying to figure out how to do something in Rails.
> Here's the situation:
> 
> I want to store in the DB (as fields) info found in a text file. I've created 
> a ruby scripted, where I "isolate" the area with the text I want(just to 
> test, or play around).
> I need a guideline on the approach...
> I want my user, to upload a text file, and then Rails should use this file to 
> isolate the needed text and store it to the DB.
> 
> Any Ideas?
> 
> PS. I consider myself a rails newbie, so excuse my unawareness in advance :)
> 
> Have a nice day,
> 
> Yours,
> G.

If you have already worked out how you're going to scrape the data from the 
text file, then the plumbing of uploading a file and post-processing it will 
depend slightly on the technique that you use to accept the uploaded file and 
store it. I built something similar (years ago, my first commercial Rails job) 
that used Paperclip to upload a PDF, and a custom "thumbnail" processor to 
extract the plain text contents from the file after it was stored on disk. I 
doubt that the code would be helpful to you, as this was Rails 2.3, and 
everything has moved a long way from that point. But the key is to accept the 
file, store it to disk, then in an after_post_process (Paperclip custom 
life-cycle event) block, do your magic to the uploaded file. 

To do this in stages, work through the Readme on 
https://github.com/thoughtbot/paperclip and get your app to accept the uploaded 
file. Then read up on custom processors in the Paperclip wiki on Github. If 
your question is about text processing, then the previous comment about Regular 
Expressions is indeed where you need to look. I can recommend Mastering Regular 
Expressions (Friedl, from OReilly Publishing).

Walter
 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/F503678E-0532-4C49-8647-66D9E57659F9%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to