start value of model

Hey fellows,

ive running a ror 3 + 1.87 app with 2 models. In one of them i want to have a start value of a string-object (f.e. "User".Object is default named to "Ray"), which should be saved as ID 1. That means if i would set up the database, then i automatically got that Object User with value "Ray" and ID 1. So how can i realize this?

create a rake task to seed the database, which you can run after your migration. here is a railscasts video:

Thank you, Rajinder Yadav!

This is exactly the thing i locked for. Now i typed in this object-creating in the migration and it works.

Best Regards, ray

Note that it is not a good idea to rely on the id of a record having a particular value (1 in this case). If you want a field containing a meaningful number then add another field to contain that number.

Colin

awesome =)

Colin Law wrote in post #956170:

Note that it is not a good idea to rely on the id of a record having a particular value (1 in this case). If you want a field containing a meaningful number then add another field to contain that number.

Colin

Ok, but my idea behind is that i only use this one value. Then i have the option to edit/update it, so there's always one value according to ID 1. No create/delete options available.

Well asides that, i have another problem. I want to associate 2 models: country and events (with country has many events and event belongs to country). I use both in the countries_controller, but i dont know how to create objects in events thorugh this controller. You got any suggestions?

Thanks for your interest, so far.

Ray Ray wrote in post #956181:

Colin Law wrote in post #956170:

Note that it is not a good idea to rely on the id of a record having a particular value (1 in this case). If you want a field containing a meaningful number then add another field to contain that number.

Colin

Ok, but my idea behind is that i only use this one value. Then i have the option to edit/update it, so there's always one value according to ID 1. No create/delete options available.

Then that's a bad idea. Colin is absolutely right: no particular ID value should ever, ever, ever be meaningful.

Well asides that, i have another problem. I want to associate 2 models: country and events (with country has many events and event belongs to country). I use both in the countries_controller, but i dont know how to create objects in events thorugh this controller. You got any suggestions?

Have you read the Associations guide yet?

Thanks for your interest, so far.

Best,

Marnen Laibow-Koser wrote in post #956183:

Ray Ray wrote in post #956181:

Then that's a bad idea. Colin is absolutely right: no particular ID value should ever, ever, ever be meaningful.

Ok, I'll think about it. Maybe i just create it without relating it to ID1.

Have you read the Associations guide yet?

Which guide do you mean? I havent read much about associations yet.

Luis