[Rails] Re: At least one entry for DB

2012-03-10 Thread Soichi Ishida
Thanks! Finally I got it done. after_save :create_first_script private def create_first_script @script = Script.new(:video_id => self.id, :startp => 0, :text => 'ToDo: ') @script.save end soichi -- Posted via http://www.ruby-forum.com/. -- You received this message because

[Rails] Re: At least one entry for DB

2012-03-09 Thread grentis
But something like @video = Video.new({.}) @script = @video.scripts.build({ :startp => 0, :text => 'ToDo: '}) @video.save doesn't work? Il giorno mercoledì 7 marzo 2012 10:01:30 UTC+1, Ruby-Forum.com User ha scritto: > > Rails 3.1.3 > > I have models and their association like, > > Video 1

Re: [Rails] Re: At least one entry for DB

2012-03-09 Thread Geoffroy Gomet
Indeed, you should save (persist) your object (script) after creating it or use the create (or create!) method instead or new: @script = Script.new(:video_id => self.id, :startp => 0, :text => 'ToDo: ') @scipt.save or @script = Script.create(:video_id => self.id, :startp => 0, :text => 'ToDo: '

Re: [Rails] Re: At least one entry for DB

2012-03-09 Thread Colin Law
On 9 March 2012 02:15, Soichi Ishida wrote: > Thanks for you answer. > >> You have to first save the @video before accessing the id, that is when >> the >> after_create or after_save is triggered. >> In your Video class, the after save has access to the @video instance >> through the self keyword

[Rails] Re: At least one entry for DB

2012-03-08 Thread Soichi Ishida
Thanks for you answer. > You have to first save the @video before accessing the id, that is when > the > after_create or after_save is triggered. > In your Video class, the after save has access to the @video instance > through the self keyword (self.id in your case). > I need to clarify this poi

[Rails] Re: At least one entry for DB

2012-03-08 Thread Geoffroy Gomet
Hey, The @video.id you are referring to is not yet existing as the @video object is not yet persisted into the db. You have to first save the @video before accessing the id, that is when the after_create or after_save is triggered. In your Video class, the after save has access to the @video ins

[Rails] Re: At least one entry for DB

2012-03-07 Thread Soichi Ishida
Thanks for your answer. I will try after_create. I have put after_create :create_first_script def create_first_script @video = Video.new(params[:video]) @script = Script.new(:video_id => @video.id, :startp => 0, :text => 'ToDo: ') end in video.rb. But I need to pass params[:vide

[Rails] Re: At least one entry for DB

2012-03-07 Thread Juan Pablo Avello
El miércoles 7 de marzo de 2012 10:01:30 UTC+1, Ruby-Forum.com User escribió: > > Rails 3.1.3 > > I have models and their association like, > > Video 1: n: Script > > When users newly create a Video, I want it to create the very first > Script entry together. > > I have put > > @scr