Ruby existing database

Hello all from Ruby newbie,

I’m sure this has been asked many times, but I can’t find the answer.

I would like to use Ruby for an existing database.

It does not use id for the primary key, and the table name are not
plural.

The tables are already loaded and filled with data.

How can I get CRUD modules for the existing tables without changing the
database structure in any way?

On Tue, 2010-04-20 at 19:50 +0200, Will R. wrote:

How can I get CRUD modules for the existing tables without changing the
database structure in any way?


inside the model class…

set_table_name :some_table_in_your_db

set_primary_key “some_primary_key_other_than_id”

Anyone else notice that http://api.rubyonrails.org has been hijacked?

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Will R. wrote:

Hello all from Ruby newbie,

I’m sure this has been asked many times, but I can’t find the answer.

I would like to use Ruby for an existing database.

It does not use id for the primary key, and the table name are not
plural.

The tables are already loaded and filled with data.

How can I get CRUD modules for the existing tables without changing the
database structure in any way?

That depends. Are you using Rails? You specified Ruby without
mentioning any other libraries…

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Yes, I have installed Rails, as well as oracle_enhanced adapter and oci8
installed.

I found an interesting link about using legacy databases:

Rails and Legacy Databases - RailsConf 2009

I did: rails --database=oracle ora_t1

I took the advice of Craig W. and set the primary key and sequence as
suggested in ctkagency.rb

ruby script\generate scaffold CTK_AGENCY AGENCY_SEQUENCE:number
AGENCY_NAME:text

I got to the localhost/3000 page ok, showing:

About your application’s environment
Ruby version 1.8.6 (i386-mswin32)
RubyGems version 1.3.6
Rack version 1.0
Rails version 2.3.5
Active Record version 2.3.5
Active Resource version 2.3.5
Action Mailer version 2.3.5
Active Support version 2.3.5
Application root C:/Ruby/rails_apps/ora_t1
Environment development
Database adapter oracle_enhanced
Database schema version 0

The next page bombed.

I think it’s because my table names have underscores, like “CTK_AGENCY”.

Processing Rails::InfoController#properties (for 127.0.0.1 at 2010-04-21
14:49:21) [GET]
e[4;36;1mSQL (328.0ms)e[0m e[0;1mselect
decode(table_name,upper(table_name),lower(table_name),table_name) name
from all_tables where owner = sys_context(‘userenv’,‘session_user’)e[0m
Completed in 421ms (View: 0, DB: 328) | 200 OK
[http://localhost/rails/info/properties]
/!\ FAILSAFE /!\ Wed Apr 21 14:49:33 -0400 2010
Status: 500 Internal Server Error
Expected C:/Ruby/rails_apps/ora_t1/app/helpers/ctkagen_cies_helper.rb
to define CtkagenCiesHelper
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:426:in
`load_missing_constant’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in
`const_missing’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in
`const_missing’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:361:in
`constantize’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in
`each’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in
`constantize’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/inflections.rb:162:in
`constantize’
C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/helpers.rb:137:in
`helper’
C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/helpers.rb:115:in
`each’
C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/helpers.rb:115:in
`helper’
C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/helpers.rb:120:in
`helper’
C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/helpers.rb:115:in
`each’
C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/helpers.rb:115:in
`helper’
C:/Ruby/rails_apps/ora_t1/app/controllers/application_controller.rb:5