I've never used watir, but if you just want to connect to the database, you have a few options:
- Use low level functions
- Use ActiveRecord
- Use Og
I'll focus on the second one:
Install activerecord with:
$ gem install activerecord
Now open your watir file, and put this in it:
Code:
require_gem 'activerecord'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "******",
:database => "dbname"
)
Now you have to create classes for your table. If you have a table called posts, you add this class:
Code:
class Post < ActiveRecord::Base
end
You can get data out like this:
Code:
Post.find(1) #=> Find post with id=1
Post.find_by_title("foo") #=> Find post with title="foo"
More info:
http://rubyonrails.com/rails/classes...cord/Base.html
Bookmarks