binro01
2008-Aug-01 19:54 UTC
Learning RoR How do I scaffold an existing dev MySQL Database
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 --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Small
2008-Aug-20 16:51 UTC
Re: Learning RoR How do I scaffold an existing dev MySQL Database
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 Small 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-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---