Forum: Ruby on Rails Creating table and importing data with Ruby

Posted by Vincent Foley (gnuvince)
on 2005-11-24 04:06
Hello,

I want to make a new Rails application, but I hate SQL.  So I wanted to 
know if it was possible to do that with Ruby itself.  To create the data 
structure, I have the following script:

require "rubygems"
require "active_record"

ActiveRecord::Base.establish_connection({
                                          :adapter => "mysql",
                                          :host => "localhost",
                                          :database => 
"cwh_development",
                                          :username => "root"
                                        })


ActiveRecord::Schema.define do

  create_table :languages do |t|
    t.column :name, :string
  end

  create_table :approvers do |t|
    t.column :name, :string
    t.column :username, :string
    t.column :password, :string
    t.column :email, :string
  end

  create_table :words do |t|
    t.column :word, :string
    t.column :definition, :text
    t.column :approver_id, :integer
    t.column :language_id, :integer
    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end

end


How does that script look?  Is there anything I could do to improve it?

Also, I have a large dictionary file with one word per line that I would 
want to import into the words table.  Is there an easy way to do that 
with Ruby and ActiveRecord?

Many thanks guys,

Vincent.
Posted by Vincent Foley (gnuvince)
on 2005-11-24 12:04
Anyone?
Posted by Jan (Guest)
on 2005-11-24 20:47
gnuvince wrote:
> Anyone?

Well, you can just put your ActiveRecord::Schema.define do..end in 
db/schema.rb and run rake db_schema_import.
Posted by Chris (Guest)
on 2005-11-25 16:48
gnuvince wrote:
> Hello,
> 
> I want to make a new Rails application, but I hate SQL.  So I wanted to 
> know if it was possible to do that with Ruby itself.  To create the data 
> structure, I have the following script:

How about ActiveRecord::Migration and rake migrate?

http://api.rubyonrails.com/classes/ActiveRecord/Migration.html
Posted by Chris <asdf@asdf.com> (Guest)
on 2005-11-28 22:05
> How about ActiveRecord::Migration and rake migrate?

Anyone?
Posted by Danny (Guest)
on 2005-11-30 15:37
gnuvince wrote:
>   create_table :languages do |t|
>     t.column :name, :string
>   end
> 
>   create_table :approvers do |t|
>     t.column :name, :string
>     t.column :username, :string
>     t.column :password, :string
>     t.column :email, :string
>   end
> ...

This looks a lot like Og, see 
http://www.rubygarden.org/index.cgi/Libraries/og_tutorial.rdoc.

Danny (blog.dannynet.net)
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.