Rails Scaffold, ActiveRecord, and table names 4

Posted by Kerry Mon, 21 May 2007 19:36:00 GMT

Looks like the Rails scaffolding doesn’t like it when your model uses a different table name from the default mapping it expects(like when accessing a legacy database model).

So if you have a model like so:

class Thing < ActiveRecord::Base
    set_table_name "some_thing"
end

Then ActiveRecord will be expecting a table called “some_thing”, however the scaffolding generator is expecting the default, which is going to be “things”(or something like that since I can’t be bothered actually generating a model called Thing).

When running your generator you’re going to end up with an error like:

error  Before updating scaffolding from new DB schema, try creating a table for your model (Thing)

Annoying as this is, you can work around it by temporarily creating the table required by the generator. Then go ahead and drop it after the generator works.

create table things ();

I’m not sure what longer term effects this causes, and if there is a better way then let me know.

Trackbacks

Use the following link to trackback from your own site:
http://blogs.divisibleprime.com/ronin/articles/trackback/870

Comments

Leave a response

  1. rach 3 days later:

    by the way, koz has said they’ve fixed this in 2.0. They’ve redone the scaffolding totally apparently :)

  2. Kerry 3 days later:

    Cool

  3. Gollo 4 days later:

    In the meantime you could try http://activescaffold.com/

  4. Gollo 4 days later:

    In the meantime you could try http://activescaffold.com/

Comments