Issue with scaffolding with rail 2.2 and mySQL


#1

Hi guys,
I’m having problems when creating basic web applications using rails
2.2 and mySQL databases.
If I create the following table in a database named
moviecritc_development:

CREATE TABLE movies (
id INT NOT NULL AUTO_INCREMENT PRIMARY_KEY,
name VARCHAR(30) NOT NULL );

and then run the following ruby commands:

rails -d mysql moviecritic (creates all the necessary files without any
issue.)

I then modify the config/database.yml to include the root password to
my database and run then ruby the following ruby command:

ruby script/generate scaffold Movie (creates usual files without error).

If i now view the db/migrate.create_movies.rb i see the following:
class CreateMovies < ActiveRecord::Migration
def self.up
create_table :movies do |t|

  t.timestamps
end

end

def self.down
drop_table :movies
end
end

It doesn’t make a reference to the name column i created! This is
reflected when i navigate to localhost:3000/movies/new i only see a
Back link and a Create Button, i don’t see a NAME FIELD INPUT.

Has anyone any ideas why this is happening?
Thanks in advance,
Stephen


#2

On Dec 13, 11:11 am, “Stephen Morrison” removed_email_address@domain.invalid
wrote:

create_table :movies do |t|

It doesn’t make a reference to the name column i created! This is
You’ve got things back to front. the migration generator does not look
at an existing table. It’s expecting that it will be creating a new
table.
The scaffolding stuff used to introspect the database but that died a
while back

These days what you should do is

  • create your rails app
  • create the database

ruby script/generate scaffold Movie name:string
This will create the migration, views and controller. The migration
will create a table with a name column called string and the views
will show that field.
then run
rake db:migrate

to run the migration (ie actually create the table).

Fred


#3

I think that’s crap. The scaffold should create the table if it does
not exist but if the table already exists then inspect the table and
generate the appropriate stuff. What a pain in the ass.

On Dec 13 2008, 7:22 am, Frederick C. removed_email_address@domain.invalid


#4

Thanks for the help! Much appreciated!