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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Vincent F. (Guest)
on 2005-11-24 05: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.
Vincent F. (Guest)
on 2005-11-24 13:04
Anyone?
Jan (Guest)
on 2005-11-24 21: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.
Chris (Guest)
on 2005-11-25 17: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/Mi...
Chris <> (Guest)
on 2005-11-28 23:05
> How about ActiveRecord::Migration and rake migrate?

Anyone?
Danny (Guest)
on 2005-11-30 16: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_t....

Danny (blog.dannynet.net)
This topic is locked and can not be replied to.