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?

On 10-10-21 07:23 AM, Ray R. wrote:

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:


Kind Regards,
Rajinder Y. | DevMentor.org | Do Good! ~ Share Freely

GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1

Thank you, Rajinder Y.!

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

Best Regards,
ray

On 21 October 2010 20:39, Ray R. [email protected] wrote:

Thank you, Rajinder Y.!

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

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

Colin L. 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.

On Thu, Oct 21, 2010 at 3:39 PM, Ray R. [email protected] wrote:

awesome =)


Kind Regards,
Rajinder Y. | DevMentor.org | Do Good! ~ Share Freely

GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1

Ray R. wrote in post #956181:

Colin L. 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
http://www.marnen.org
[email protected]

Luis

http://ww.saffie.ca

Marnen Laibow-Koser wrote in post #956183:

Ray R. 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.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]