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 > > @script = Script.new(:video_id => @video.id, :startp => 0, :text => > 'ToDo: ') > > in Video controller, 'new' action, but it doesn't work (:startp value is > determined for the first one). > > How can I create a Script entity together with Video? > > Also, if possible, I want that first Script entry to be undestroyable. > Do you think I can do it? > > Thanks in advance, > > soichi > > -- > Posted via http://www.ruby-forum.com/. >
You can use either an after_create on the model or an observer which observes a Video creation. Personally, I usually prefer observers which seem less intrusive to me, giving a better to make it active or unactive, but some people think the other way. To make your first script undestroyable, you can add a column to the model or a 'before_destroy' which checks if its the first Script created for a given Video, a method to check this same condition and hide 'destroy' links... there is a lot of ways to do this. -- 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/-/AF4bSfV5ic4J. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

