I'm just now getting around to trying out Rails 2. I used Rails 1
briefly. Back then I was able to start with an existing database that
followed ActiveRecord conventions, run a few simple commands, and get
a basic web app. up and running. It seems that has changed in Rails 2.
Am I required to describe the columns of my tables for Rails 2 and/or
modify generated code? I really want Rails to get information about
the columns from my database schema and generate starting code for me.
If I have to describe the tables myself, can someone point me at some
documentation that describes the steps?
Rails 2 does everything rails 1.2 does and more.
It does use SQLite3 however and you still have to set up migrations
and database relations in your model.
maybe read activerecord in the API... not quite sure what you're
asking.
Rails 2 does everything rails 1.2 does and more.
It does use SQLite3 however
I noticed that, so I ran "rails -dmysql addressbook" to create my
addressbook application.
and you still have to set up migrations
and database relations in your model.
I understand the part about setting up database relations in my model
classes, but I didn't used to have to set up migrations. Is there a
way to generate the first migration from existing database tables?
Maybe this is the key part I'm missing.
maybe read activerecord in the API... not quite sure what you're
asking.
I know pretty much about ActiveRecord. I have lots of Ruby code that
is correctly accessing and modifying my database using ActiveRecord
without using Rails outside the context of a web app. Now I'm trying
to use that same database with Rails.
A migration is a change to the structure of a database, if you already
have a database structure and you just want to access it in rails you
don't need a migration.
Try: ruby script/generate model --skip-migration SomeExistingTable
Note that rails makes assumptions about the tables it uses to store
model data. You will need to override some of these assumptions if
your DB schema isn't what rails is after. For example, see:
set_primary_key (http://localhost/rails-2.0.2-api/classes/ActiveRecord/
Base.html#M001400), set_table_name (http://localhost/rails-2.0.2-api/
classes/ActiveRecord/Base.html#M001399).
A migration is a change to the structure of a database, if you already
have a database structure and you just want to access it in rails you
don't need a migration.
Try: ruby script/generate model --skip-migration SomeExistingTable
For anyone else interested in trying this, use two dashes before skip-migration.
However, this still doesn't work. The generated model .rb files and
view .erb files still don't know about the columns in my tables. I'm
looking for a way to get those generated by automatically obtaining
information about the columns from my database rather than having to
explicitly tell Rails about the columns. Is that possible? It was in
earlier versions of Rails.
You might want to have a look at the dynamic_scaffolding plugin, which was extracted from rails for 2.0
that will only fiddle with the view files - nothing will happen to the model (but it's never done anything there)
I understand that many people feel that dynamic scaffolding is only
useful for demos, not real web apps. I think what I really want is
code generation for models. I want my models and views to be generated
with content related to the fields in my tables. Is that supported out
of the box by Rails 2?