[Rails] Ruby existing database

17 views
Skip to first unread message

Will Raffaele

unread,
Apr 20, 2010, 1:50:08 PM4/20/10
to rubyonra...@googlegroups.com
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?
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Craig White

unread,
Apr 20, 2010, 2:03:51 PM4/20/10
to rubyonra...@googlegroups.com
On Tue, 2010-04-20 at 19:50 +0200, Will Raffaele 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?
----
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.

Marnen Laibow-Koser

unread,
Apr 20, 2010, 6:09:34 PM4/20/10
to rubyonra...@googlegroups.com
Will Raffaele 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
mar...@marnen.org

Will Raffaele

unread,
Apr 21, 2010, 3:06:08 PM4/21/10
to rubyonra...@googlegroups.com
Yes, I have installed Rails, as well as oracle_enhanced adapter and oci8
installed.

I found an interesting link about using legacy databases:

http://www.slideshare.net/napcs/rails-and-legacy-databases-railsconf-2009

I did: rails --database=oracle ora_t1

I took the advice of Craig White 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]
[4;36;1mSQL (328.0ms) [0m [0;1mselect
decode(table_name,upper(table_name),lower(table_name),table_name) name
from all_tables where owner = sys_context('userenv','session_user') [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
Reply all
Reply to author
Forward
0 new messages