# Learning RoR How do I scaffold an existing dev MySQL Database

**URL:** <https://www.ruby-forum.com/t/learning-ror-how-do-i-scaffold-an-existing-dev-mysql-database/144779>\
**Category:** Rails\
**Created:** [August 1, 2008, 11:46pm UTC](https://www.ruby-forum.com/t/learning-ror-how-do-i-scaffold-an-existing-dev-mysql-database/144779 "2008-08-01T23:46:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![binro01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e8cbc/32.png) [@binro01](https://www.ruby-forum.com/u/binro01)\
**Post date:** [August 1, 2008, 11:46pm UTC](https://www.ruby-forum.com/t/learning-ror-how-do-i-scaffold-an-existing-dev-mysql-database/144779/1 "2008-08-01T23:46:00Z")

</div>

Hi All,

I learned how to create databases via migrations with RoR, but now I  
want to start building an application based on an existing database  
that didnt follow rails standards (ie pluralization rules on tables)

I have a dev database named core with a table called classmst

I want to build a new application where I have a modle that will  
access classmst, and then I want to use scaffold to build a quick  
controller/view for some CRUD manipulations on classmst.

What would be the steps I need to take to deal with this non-Rails  
standard database table to make a quick scaffold CRUD application on  
this table so that I can see its existing data and perform Add/Updates  
and Deletes

Rob

---

<div class="post-metadata">

**Author:** ![binro01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e8cbc/32.png) [@binro01](https://www.ruby-forum.com/u/binro01)\
**Post date:** [August 20, 2008, 6:51pm UTC](https://www.ruby-forum.com/t/learning-ror-how-do-i-scaffold-an-existing-dev-mysql-database/144779/2 "2008-08-20T18:51:27Z")

</div>

I’m going to guess on this one because I’ve done a fair bit of data  
munging from legacy DB schemas to RoR using active record, but not much  
in the way of scaffolds. My guess is that if you use script/generate  
scaffold in the usual way to get your models and views set up, then you  
can add bits and pieces to the model definitions to make it read legacy  
schema. There are two ways to do this, if you only need to read stuff  
then an easy thing to do it to create a view in the db that presents  
things as Active Record wants to see them, i.e. id for the primary key  
and pluralised table names. If your DB handles updateable views then you  
might find that good enough. The other way is to do it entirely in  
Rails. For example you can set the primary key field in your model with  
set\_primary\_key e.g.

class MyModel \<ActiveRecord::Base  
set\_primary\_key “something\_other\_than\_plain\_old\_id”  
end

and the table name  
class MyModel \<ActiveRecord::Base  
set\_table\_name “something\_other\_than\_my\_models”  
end

You get the general idea. At risk of promoting a commercial product, I  
recommend getting yourself a copy of “Pro Active Record”, which has a  
whole section on using ActiveRecord with legacy schema and all the  
little configuration options you can use.

Remember that RoR is opinionated software, it has lots of useful  
defaults, but those defaults can usually be overridden if you need  
things to work outside the RoR opinions.

Have fun

John S.

binro01 wrote:

> Hi All,
> 
> I learned how to create databases via migrations with RoR, but now I  
> want to start building an application based on an existing database  
> that didnt follow rails standards (ie pluralization rules on tables)
> 
> I have a dev database named core with a table called classmst
> 
> I want to build a new application where I have a modle that will  
> access classmst, and then I want to use scaffold to build a quick  
> controller/view for some CRUD manipulations on classmst.
> 
> What would be the steps I need to take to deal with this non-Rails  
> standard database table to make a quick scaffold CRUD application on  
> this table so that I can see its existing data and perform Add/Updates  
> and Deletes
> 
> Rob
