Forum: Ruby on Rails Legacy Table works-except edit?

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.
4f0c9dc6cf209d996ab24502ee5c7f2f?d=identicon&s=25 Bothari (Guest)
on 2006-01-04 18:29
(Received via mailing list)
Greetings,

I'm trying to put a Rails face on a Legacy Oracle 10 table.  I am
currently setting the table_name and primary_key, and I get the list
and show to work fine.

However, when I hit edit I just get the Editing <table name>, Edit
button, Show, and Back.  None of the fields are rendered.

Why would I be able to show these fields in the show and list, but not
edit them in the edit?  My DB user has the power to edit them via
TOAD.

Thanks,
Joe
4f0c9dc6cf209d996ab24502ee5c7f2f?d=identicon&s=25 Bothari (Guest)
on 2006-01-04 19:03
(Received via mailing list)
I failed to mention that the _form.rthml is
<%= error_messages_for 'ref_specification' %>

<!--[form:ref_specification]-->
<!--[eoform:ref_specification]-->

But why dosen't it have the setters in it?  The editable coulmns are
all varchar and date.

Thanks,
Joe

On 1/4/06, Bothari <bothari@gmail.com> wrote:
> edit them in the edit?  My DB user has the power to edit them via
> TOAD.
>
> Thanks,
> Joe
>


--
"For a new software system, the requirements will not be completely
known until after the users have used it."  Humphrey's Requirements
Uncertainty Principle.
4f0c9dc6cf209d996ab24502ee5c7f2f?d=identicon&s=25 Bothari (Guest)
on 2006-01-04 20:21
(Received via mailing list)
Just to keep things moving I went ahead and filled in all the values I
wanted to update.

However, now I have a different problem.  When I try to create a new
object it's looking for a sequence that doesn't exist.  I want to use
a user-entered sequence.  I know this is generally a bad idea.

I've seen some reference to before_validate_on_create, but I don't
know what to do with it.

Thanks,
Joe

On 1/4/06, Bothari <bothari@gmail.com> wrote:
> Joe
> >
> "For a new software system, the requirements will not be completely
> known until after the users have used it."  Humphrey's Requirements
> Uncertainty Principle.
>


--
"For a new software system, the requirements will not be completely
known until after the users have used it."  Humphrey's Requirements
Uncertainty Principle.
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-01-05 19:57
(Received via mailing list)
On 1/4/06, Bothari <bothari@gmail.com> wrote:
> Thanks,
> > all varchar and date.
> > >
> > > However, when I hit edit I just get the Editing <table name>, Edit
> > > button, Show, and Back.  None of the fields are rendered.
> > >
> > > Why would I be able to show these fields in the show and list, but not
> > > edit them in the edit?  My DB user has the power to edit them via
> > > TOAD.
> > >

Make sure that you've either got the physical tables in the user
schema your Rails app runs as, or else you have synonyms for them.

For example, if your userid in database.yml is "rails", and you're
looking for a table called "specifications".. then this has to work:
(This is the actual query that the OCIAdapter is executing)

select column_name, data_type, data_default, nullable,
 decode(data_type, 'NUMBER', data_precision, 'VARCHAR2', data_length,
null) as length,
 decode(data_type, 'NUMBER', data_scale, null) as scale
 from user_catalog cat, user_synonyms syn, all_tab_columns col
 where cat.table_name = 'SPECIFICATIONS'
 and syn.synonym_name (+)= cat.table_name
 and col.table_name = nvl(syn.table_name, cat.table_name)
 and col.owner = nvl(syn.table_owner, user)

If you can wade through that mess, you can see that the table name has
to either appear in USER_CATALOG, or USER_SYNONYMS, or both, in order
for Rails to fetch the proper list of attributes for your model
objects.

If the table is in the "OTHER" schema instead of the "RAILS" schema,
you'll need to do:
CREATE SYNONYM RAILS.SPECIFICATIONS FOR  OTHER.SPECIFICATIONS
Do that for every model table, and you should be good to go.

It would be nice if there were a config option for the Oracle adapter
that let you specify which schema the tables are in. That way you
could do:  ActiveRecord::Base.default_schema = "OTHER"
..and ActiveRecord would qualify all its SQL queries with
OTHER.TABLE_NAME

To override the sequence name, put this in your model:

class Specification < ActiveRecord::Base
  set_sequence_name "crazy_legacyseq"
end
This topic is locked and can not be replied to.