Rebin J. wrote in post #1034085:
I have experience with symfony frame work thats why asking the
question here.Excuse me if I am wrong
This reply is for your future reference, and are merely suggestions…
I have created a schema.rb file with definitions of 50 files and
schema:load did creation of the tables.
It is typical for Rails developers to generate database tables as a
series of migrations where tables are added throughout the development
cycle of a project. The framework is designed this way because most
Rails developers use Behavior/Test Driven Development (BDD/TDD)
- I want to create models of these tables from schema.rb without
entering the fields names in the command line. Is this possible?
Say you have a “users” table in your database… Following is what the
associated model file would look like:
class User < ActiveRecord::Base
Yep, that is it. This is what “rails generate model user first:name
last:name” would generate no matter how many fields you add to the
underlying database table.
Should be pretty easy for you to write a Ruby script that would generate
your 50 model files.
- I want to create controllers and views also with respect to it,
That could be tricky since that’s what “rails generate scaffold…” was
designed to do. If you want to stray from the well defined path the
framework creators provided for you, and blaze your own trail, then
you’ve got a lot more work ahead of you than typical Rails developers
who follow the path.
db:migrate will destroying my well defined database table structure.
IS there any way to keep the schema.rb without overwriting it?
Yes. That’s correct. Hence the warning in
6.1 What are Schema Files for?
Migrations, mighty as they may be, are not the authoritative source for
your database schema. That role falls to either db/schema.rb or an SQL
file which Active Record generates by examining the database. They are
not designed to be edited, they just represent the current state of the