Changing Scafflolds

Basically I’ve been creating various RoR (ruby on rails) applications
and I cant figure out how to add properties to an already existing
scaffold; I have ended up destroying and messing up two projects that
I’ve worked hard on so far in trying to do this and realised I need
some help trying to edit these.

Please Help,

Joe

Don’t you just use the scaffold, as a bases, and the create the rest
manual?

What is your exact problem:
What have you done?
What are you missing/trying to do?

Give concrete examples.

/SG

For example if I created a forum with RoR and decided to have a forum,
thread, and post scaffold, and they each has their own properties;
Lets say the forum scaffold was made with these parameters “forum
name:string number:integer”. However if I wanted to add another
property to the forum scaffold (for example if I wanted to add
“password:string”) how would I do this?

At the moment I have something similar to this (well its different,
but never the less uses scaffolds kind of like this) and I need to add
a new property. Ive tried creating over the top of it with its already
existing parameters plus the ones I want to add (for example “forum
name:string number:integer password:string”) however when I do this I
then get this error when I attempt to migrate the database (categories
is the scaffold I’m trying to add properties to):

rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table “categories” already exists: CREATE TABLE
“categories” (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “name”
varchar(255), “image” varchar(255), “created_at” datetime,
“updated_at” datetime)

(See full trace by running task with --trace)

I really need to be able to:

1)Get past this error.
2)Figure out how to add properties to scaffolds.

Thanks In Advance,

Joe

On 21 March 2010 12:02, [email protected] wrote:

For example if I created a forum with RoR and decided to have a forum,
thread, and post scaffold, and they each has their own properties;

rake aborted!
An error has occurred, this and all later migrations canceled:

You’ve got some terminology problems there, that are confusing things
a little. What you’re calling “scaffolds” are really “migrations”.

“Scaffolding” is the combination of views, migrations, models and
controllers that Rails can create for you to give you a bootstrap into
a working application.

By the sounds of it, you need to use “add_column” in your new migration.
Have a look at some of the resources found through Google, or at p.71
of the “Agile Web D. With Rails” book.
http://www.google.co.uk/search?q=rails+migration+add_column

Aha, thanks! ill look into this (I really dont know any of the
terminology, when I created the stuff I saw the word scaffold and
assumed this was what to call it :P)

If I have any further problems ill ask.

Thanks,

Joe

Ok, I seem to have a problem already.

So first of all with these things, can I just change it in db/migrate/
WhateverFile.rb ?
Then when I have changed it how do I put these changes into action?

Also I cant seem to find how this could help me solve the error:

rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table “categories” already exists: CREATE TABLE
“categories” (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “name”
varchar(255), “image” varchar(255), “created_at” datetime,
“updated_at” datetime)

(See full trace by running task with --trace)

Although I assume it could in some way (since it has to do with the
database, and rake etc)…

Please Help,

Thanks In Advance,

Joe

Aha, thanks! ill look into this (I really dont know any of the
terminology, when I created the stuff I saw the word scaffold and
assumed this was what to call it :P)

If I have any further problems ill ask.

Thanks,

Joe

Ok, I seem to have a problem already.

So first of all with these things, can I just change it in db/migrate/
WhateverFile.rb ?
Then when I have changed it how do I put these changes into action?

Also I cant seem to find how this could help me solve the error:

rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table “categories” already exists: CREATE TABLE
“categories” (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “name”
varchar(255), “image” varchar(255), “created_at” datetime,
“updated_at” datetime)

(See full trace by running task with --trace)

Although I assume it could in some way (since it has to do with the
database, and rake etc)…

Please Help,

Thanks In Advance,

Joe

On 21 March 2010 13:40, [email protected] wrote:

Ok, I seem to have a problem already.

So first of all with these things, can I just change it in db/migrate/
WhateverFile.rb ?
Then when I have changed it how do I put these changes into action?

I suggest you have a look at the rails guides at
http://guides.rubyonrails.org/. Start with Getting Started, not
surprisingly, then the next one is Database Migrations which should
sort out your current problems. Then move on and work you way through
the others.

The ones on ActiveRecord Associations and Debugging are compulsory
reading.

Colin

Ok, I seem to have a problem already.

So first of all with these things, can I just change it in db/migrate/
WhateverFile.rb ?
Then when I have changed it how do I put these changes into action?

Also I cant seem to find how this could help me solve the error:

rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table “categories” already exists: CREATE TABLE
“categories” (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “name”
varchar(255), “image” varchar(255), “created_at” datetime,
“updated_at” datetime)

(See full trace by running task with --trace)

Although I assume it could in some way (since it has to do with the
database, and rake etc)…

Please Help,

Thanks In Advance,

Joe

And remember to use

Great for getting started.

/SG

Ok, So I figure I have to roll the database back and then migrate it
again.

However it just isnt doing anything when I call “rake db:rollback”, or
even specify a STEP:

rake db:rollback STEP=4
(in C:/Users/user/Documents/Aptana Studio Workspace/ProductCatalog)
rake db:rollback STEP=10
(in C:/Users/user/Documents/Aptana Studio Workspace/ProductCatalog)
rake db:migrate
(in C:/Users/user/Documents/Aptana Studio Workspace/ProductCatalog)
== CreateCategories: migrating
===============================================
– create_table(:categories)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table “categories” already exists: CREATE TABLE
“categories” (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “name”
varchar(255), “image” varchar(255), “created_at” datetime,
“updated_at” datetime)

(See full trace by running task with --trace)

I just cant figure out why it wont rollback…

Please Help,

Thanks In Advance,

Joe

NEVER MIND. I was being an idiot. I just deleted the old migration
file that was causing the problems; and then created a new migration
file to get the new stuff in…

Thanks Guys,

-Joe