# Interact with the database from a simple ruby script

**URL:** <https://www.ruby-forum.com/t/interact-with-the-database-from-a-simple-ruby-script/107244>\
**Category:** Rails\
**Created:** [June 19, 2007, 4:22pm UTC](https://www.ruby-forum.com/t/interact-with-the-database-from-a-simple-ruby-script/107244 "2007-06-19T16:22:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean-Francois](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@Jean-Francois](https://www.ruby-forum.com/u/Jean-Francois)\
**Post date:** [June 19, 2007, 4:22pm UTC](https://www.ruby-forum.com/t/interact-with-the-database-from-a-simple-ruby-script/107244/1 "2007-06-19T16:22:54Z")

</div>

Hi,

I have a simple rails application with a model. The data that needs to  
be entered in the database comes from an external application which I  
can parse using a standard ruby script. What would be the proper way  
to handle model/database interactions from an external ruby script?  
Should I use rake tasks instead?

Thanks!

JF

---

<div class="post-metadata">

**Author:** ![Jean-Francois](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@Jean-Francois](https://www.ruby-forum.com/u/Jean-Francois)\
**Post date:** [June 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/interact-with-the-database-from-a-simple-ruby-script/107244/2 "2007-06-19T16:30:35Z")

</div>

Jean-Francois wrote:

> Hi,
> 
> I have a simple rails application with a model. The data that needs to  
> be entered in the database comes from an external application which I  
> can parse using a standard ruby script. What would be the proper way  
> to handle model/database interactions from an external ruby script?  
> Should I use rake tasks instead?
> 
> Thanks!
> 
> JF

Read this:  
[http://www.railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial](http://www.railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial)  
and maybe this: [My Rails Toolbox — err.the\_blog](http://errtheblog.com/post/33)

The go ahead and write your rake tasks. 🙂

Emmanuel O.

---

<div class="post-metadata">

**Author:** ![Jean-Francois](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@Jean-Francois](https://www.ruby-forum.com/u/Jean-Francois)\
**Post date:** [June 19, 2007, 4:33pm UTC](https://www.ruby-forum.com/t/interact-with-the-database-from-a-simple-ruby-script/107244/3 "2007-06-19T16:33:55Z")

</div>

puts everything togheter, something like:

require ‘rubygems’  
require\_gem ‘activerecord’

ActiveRecord::Base.establish\_connection({  
:adapter =\> ‘mysql’,  
:database =\> ‘mydb’,  
:username =\> ‘user’,  
:password =\> ‘password’  
})

class MyTable \< ActiveRecord::Base  
end

…your ruby script that parse here…

2007/6/19, Jean-Francois [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Jean-Francois](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@Jean-Francois](https://www.ruby-forum.com/u/Jean-Francois)\
**Post date:** [June 20, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/interact-with-the-database-from-a-simple-ruby-script/107244/4 "2007-06-20T16:30:51Z")

</div>

Also check out

[http://benlog.org/2007/6/18/stepping-off-the-rails-with-rack](http://benlog.org/2007/6/18/stepping-off-the-rails-with-rack)
