Topic: "Legacy" database and scaffold

Although I haven't tried it, I'm sure setting up the standard rails cookbook database and instant-app works just dandy.  So I'm sure that rails really does allow an application to be set up in 10% of the time required to set one up under other app frameworks.  But I'm not interested in toy demos.

In the real world, systems that operate by the grace of naming conventions simply do not work.  Especially when the naming convention applies to database table names (and incidentally is exactly wrong -- table names should be singular if you really care about it one way or the other).

I have tried everything I can think of or google, and I can't get scaffolding with existing database names to work.  It does seem odd to me that the most natural-seeming thing I want to do -- set up rails in 10% of the time, but running from one actual existing table, instead of from a toy table -- seems impossible.  Or at least very difficult.  Certainly not something that can be done (by me) in 10% of the time.

I've come away from my first few days of tinkering with rails with the impression that it is a toy (but a magnificently hyped one!).  Can anyone tell me what I'm missing -- what's the magic trick of hanging a rails app on an existing table using scaffolding?  Not using scaffolding is an unacceptable answer -- then I'll be spending ages trying to understand the ruby/rails nuances that the hype has promised me I don't need to wrestle with.

Re: "Legacy" database and scaffold

What have you tried so far?

Have you tried setting
ActiveRecord::Base.pluralize_table_names=false in your
config/environment.rb

Have you tried generating the model and then providing
a
set_table_name "existing_table_name"
override in the model before scaffolding?  Similarly for primary key naming issues.  If you follow a tablename_id concention in your legacy database for primary keys, you can also setup that default in the environment.rb, file, etc

Personally, I find the scaffolding to be a time-waster and I find I'm faster doing it the way I want from the start (and still faster than I was in either PHP or Java).  I only takes about 2 days of playing with rails to understand what magic scaffolding does for you.

However if you've already made the decision that learning the nuances of Ruby isn't worth your while, then I'd probably move on from Rails....  Ruby is the reason I'm putting up with some of the conventions/opinions in Rails that I'm not a big fan of.... Ruby is why I'm more productive (and I didn't know Ruby before I started working with rails about 3 weeks ago....)

Last edited by NielsenE (2006-06-17 19:41:46)

My RoR journey  -- thoughts on learning RoR and lessons learned in applying TDD and agile practices.

Re: "Legacy" database and scaffold

In a word, yes.  I tried those.  Maybe I never got those kludges done correctly.  Or maybe I'm not talking to the database at all.  I wouldn't know.  (Error messages in rails are absent or cryptic -- useless -- in my limited experience.)

Have you actually succeeded at hanging a simple app on an existing database table using scaffolding?  Has anyone?

Re: "Legacy" database and scaffold

Reading my own posts, I see that I sound like I'm not at all thrilled by rails and that I'm probably wasting your time with my negative attitude.  That's probably accurate.  Ignore me.  I'm going to give up on rails and go away.

Re: "Legacy" database and scaffold

Yes, I have had some success at hanging scaffolding on non-rails-friendly database schemas.  I wouldn't call them legacy databases, as I created them solely to try out these types of issues when I was starting with rails.

However my "real" projects are all green-field development so I'm following the expected conventions in those....

I just tried a simple test, I created a new rails project
rails legacy
edited environment to use not pluralize table names
create a new database with a single table
  CREATE TABLE pet (
  id SERIAL PRIMARY KEY,
  name text
);
script/generate scaffold Pet Admin

the scaffolded code works, and on visual inspection it looks correct.

I dropped the database and repeated the process after setting
  ActiveRecord::Base.primary_key_prefix_type=:table_name_with_underscore

and changed the primary key to pet_id.

Still successful.

So in simple legacy cases, where the legacy database mainly follows _some_ conventions its possible to get scaffolding to work with very simple one-time tweaks.  If the primary keys are more "erratic" in their naming, then you'll have to generate the model first, and then scaffold after overriding the pkey.

I'd suggest trying to follow one of the tutorials, just to make sure you are talking to your database, etc  Or post a table definition that rails doesn't want to scaffold and we can see what's confusing it.

My RoR journey  -- thoughts on learning RoR and lessons learned in applying TDD and agile practices.

Re: "Legacy" database and scaffold

Thanks very much, but no matter what I try it does nothing.  It spits out a few cryptic lines of the sort I've seen in what passes for documentation, but it has generated nothing useful that I can see.  No error messages or indications of any sort that things have not functioned properly.  I still think it's my database connection, but I would expect _some_ error report. 

I can't use this product.  Critical reliance on command lines, weak to non-existent docs, and silent dysfunction.  Amazing what hype will make people adore.

Thanks very much for your help anyway.

Re: "Legacy" database and scaffold

I understand your frustration, but your claim "Amazing what hype will make people adore." is personally insulting to me and everyone at this forum.

Re: "Legacy" database and scaffold

Violates the fourth law, too. wink

Hopefully rfr will reconsider and not give up.

One just needs to look at any of the beautiful apps at 37Signals to realize that RoR is a very capable framework in the hands of the right developer. smile

Josh Catone helps run this place
Rails Forum - Rails Jobs

Re: "Legacy" database and scaffold

However, there is a point in the OP's question/viewpoint -- the rails community could benefit from a few more tutorials written for people who are working with legacy databases.  Its easy for people to throw together a green-field demo application using all the magic of scaffolding and such, and just let the rails conventions do their thing.  I know I didn't bother giving rails a chance for a long while -- the hype and examples made it look like it was a very tightly focused tool for small applications.  I'm a database guy so a lot of it sounded too simplistic.  However after giving it a chance, I realize that, with a few exceptions, my misgivings were unfounded, and even with those misgivings the productivity gains are worth some "philosophical" compromises.

Many people also discuss the "post-depot" syndrome from AWDWR -- Depot feels easy and most people leave it feeling like the understand it, but as soon as they try to apply it, many get lost.

This is one reason why I really hope this forum takes off -- I've always found forums better than mailing lists or IRC for helping _educate_ developers versus solving a problem.

My RoR journey  -- thoughts on learning RoR and lessons learned in applying TDD and agile practices.

10

Re: "Legacy" database and scaffold

thabenksta wrote:

I understand your frustration, but your claim "Amazing what hype will make people adore." is personally insulting to me and everyone at this forum.

I apologize.  Thanks, sincerely, to anyone here who offered time and effort to answer my griping and help with the problems I've had with rails.

Re: "Legacy" database and scaffold

NielsenE wrote:

...the rails community could benefit from a few more tutorials written for people who are working with legacy databases...

We could also benefit from coming up with some better guides to "how to debug your first Rails app".  500 errors have been horrible to me - I hope that future Rails newbs don't have to suffer through what many of us did.

I totally respect that rfr hasn't had this "easy" framework been easy for him.  It's an awesome thing but there's been a dearth of good help out there.