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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10-10-21 07:23 AM, Ray Ray 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: http://railscasts.com/episodes/179-seed-data -- Kind Regards, Rajinder Yadav | 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 October 2010 20:39, Ray Ray <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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.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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Oct 21, 2010 at 3:39 PM, Ray Ray <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 > > -- > Posted via http://www.ruby-forum.com/. >awesome =) -- Kind Regards, Rajinder Yadav | 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. > > ColinOk, 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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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.> > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
http://guides.rubyonrails.org/association_basics.html Luis -- http://ww.saffie.ca -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.