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 instance through the self keyword (self.id in your case).
Another solution to your problem would be to use nested attributes (see accepts_nested_attributes_for in the rails docs) I hope this helps. Regards Geoffroy Op donderdag 8 maart 2012 03:41:40 UTC+1 schreef Ruby-Forum.com User het volgende: > > 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[:video] somehow... > > /videos/_form.html.erb (generated by scaffold) should do it, correct? > > <%= form_for(@video) do |f| %> > > <div class="field"> > <%= f.label :title %><br /> > <%= f.text_field :title %> > </div> > <div class="field"> > <%= f.label :url %><br /> > <%= f.text_field :url %> > </div> > <div class="actions"> > <%= f.submit %> > </div> > <% end %> > > > I am not sure how to pass the video object from here. > Could anyone give me tips? > > soichi > > -- > 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 view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/h-vGTdmMb8IJ. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.