# Automating a ruby script

**URL:** <https://www.ruby-forum.com/t/automating-a-ruby-script/143944>\
**Category:** Rails\
**Created:** [July 24, 2008, 2:09am UTC](https://www.ruby-forum.com/t/automating-a-ruby-script/143944 "2008-07-24T02:09:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blakes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@Blakes](https://www.ruby-forum.com/u/Blakes)\
**Post date:** [July 24, 2008, 2:09am UTC](https://www.ruby-forum.com/t/automating-a-ruby-script/143944/1 "2008-07-24T02:09:07Z")

</div>

I have been working on an application that takes a text file and  
parses information from it. I have the script in my script folder,  
and can run it if I enter ‘script/parser file.txt’. I am using the  
‘attachment\_fu’ plug-in to upload the text file to my public folder  
(admittedly not the best place to keep raw data, but I will work that  
out in time). Once I have that file uploaded, and verified it using  
the ‘validates\_as\_attachment’, how do I get the script to  
automatically parse the file?

Would it be possible to create a helper that runs a console command?  
It seems possible, but not the best way. Does anyone have a better  
idea?

Thank you so much for any help you can give. I have been racking my  
brain trying to figure this out.

---

<div class="post-metadata">

**Author:** ![Blakes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@Blakes](https://www.ruby-forum.com/u/Blakes)\
**Post date:** [July 24, 2008, 2:32am UTC](https://www.ruby-forum.com/t/automating-a-ruby-script/143944/2 "2008-07-24T02:32:30Z")

</div>

Is there any particular reason that you wrote the script as an  
external command instead of simply write that code as a class that you  
can call your parsing methods on?

class AttachmentParser  
def parse(file)  
…your parsing code here…  
end  
end

You could put this class either in a directory where Rails will load  
it automatically or you can require it wherever you want to do your  
parsing.

---

<div class="post-metadata">

**Author:** ![Blakes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@Blakes](https://www.ruby-forum.com/u/Blakes)\
**Post date:** [July 28, 2008, 9:27pm UTC](https://www.ruby-forum.com/t/automating-a-ruby-script/143944/3 "2008-07-28T21:27:55Z")

</div>

The parser was originally set up to run from the Terminal, but now I  
want it automated. Your way worked perfectly, and I even added the  
method to be called from the script, and now it will work either way.  
Thanks again.

On a different note, you don’t happen to know how to link to an index  
view in another folder?
