Rails 3.1.3 Related to my old thread http://www.ruby-forum.com/topic/3802905#new video.rb has after_save :create_first_script private def create_first_script @script = Script.new(:video_id => self.id, :startp => 0, :text => ''ToDo: '') @script.save end The problem is that after destroying all data, a freshly created video DOES create the first Script, but the following videos DO NOT. I have added User table so that Video and Script classes are only editable for Users that own them. The association is User:1 -- n:Video:1--n:Script To be honest, I have no idea which part of my code is causing this problem. I am sure the information provided here is not enough. I appreciate if you point out what I need to show you in order to gain some help. Thanks in advance. 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 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.
Do know why fresh created video can create script but following video does not. What i am 100% sure is that after_save is not right place to put this logic. Cause any object''s update will invoke after save, so new script will created every update. -- rubyonrailsx Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Friday, March 16, 2012 at 1:16 PM, Soichi Ishida wrote:> Rails 3.1.3 > > Related to my old thread > > http://www.ruby-forum.com/topic/3802905#new > > video.rb has > > after_save :create_first_script > private > def create_first_script > @script = Script.new(:video_id => self.id, :startp => 0, :text => > ''ToDo: '') > @script.save > end > > > The problem is that after destroying all data, a freshly created video > DOES create the first Script, but the following videos DO NOT. > > I have added User table so that Video and Script classes are only > editable for Users that own them. > The association is > > User:1 -- n:Video:1--n:Script > > To be honest, I have no idea which part of my code is causing this > problem. I am sure the information provided here is not enough. I > appreciate if you point out what I need to show you in order to gain > some help. > > Thanks in advance. > > 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
Looking at the log... The first one is successful in creating the first Script, the second one is not. SQL is not working for the second but certainly after_save method is called..(''first script action HERE!!!!!!'' is logger.info). Does it help? soichi Started POST "/videos" for 127.0.0.1 at 2012-03-16 14:08:42 +0900 Processing by VideosController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"/AYk7ocjjteBKH8fDpQZ7FKzme/0nSsT2kalq8FgI18=", "video"=>{"title"=>"Rush Limbaugh Calls a Female Georgetown Student, Sandra Fluke, a ''Slut''", "url"=>"http://www.youtube.com/watch?v=3KNpn-XGM04", "language"=>"1", "genre"=>"news"}, "commit"=>"Create Video"} User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 SQL (0.7ms) INSERT INTO "videos" ("created_at", "genre", "language", "title", "updated_at", "url", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", Fri, 16 Mar 2012 14:08:43 JST +09:00], ["genre", "news"], ["language", "1"], ["title", "Rush Limbaugh Calls a Female Georgetown Student, Sandra Fluke, a ''Slut''"], ["updated_at", Fri, 16 Mar 2012 14:08:43 JST +09:00], ["url", "http://www.youtube.com/watch?v=3KNpn-XGM04"], ["user_id", 1]] first script action HERE!!!!!! (0.2ms) SELECT 1 FROM "scripts" WHERE "scripts"."startp" = 0.0 LIMIT 1 SQL (0.5ms) INSERT INTO "scripts" ("created_at", "startp", "text", "updated_at", "video_id") VALUES (?, ?, ?, ?, ?) [["created_at", Fri, 16 Mar 2012 14:08:43 JST +09:00], ["startp", #<BigDecimal:102b7cd18,''0.0'',9(36)>], ["text", "ToDo: "], ["updated_at", Fri, 16 Mar 2012 14:08:43 JST +09:00], ["video_id", 11]] Redirected to http://localhost:3001/videos/11 Completed 302 Found in 211ms Started POST "/videos" for 127.0.0.1 at 2012-03-16 14:08:59 +0900 Processing by VideosController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"/AYk7ocjjteBKH8fDpQZ7FKzme/0nSsT2kalq8FgI18=", "video"=>{"title"=>"bergman trailer persona", "url"=>"http://www.youtube.com/watch?v=XZsU_ACYSAA", "language"=>"1", "genre"=>"persona"}, "commit"=>"Create Video"} User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 SQL (0.7ms) INSERT INTO "videos" ("created_at", "genre", "language", "title", "updated_at", "url", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", Fri, 16 Mar 2012 14:09:00 JST +09:00], ["genre", "persona"], ["language", "1"], ["title", "bergman trailer persona"], ["updated_at", Fri, 16 Mar 2012 14:09:00 JST +09:00], ["url", "http://www.youtube.com/watch?v=XZsU_ACYSAA"], ["user_id", 1]] first script action HERE!!!!!! (0.2ms) SELECT 1 FROM "scripts" WHERE "scripts"."startp" = 0.0 LIMIT 1 Redirected to http://localhost:3001/videos/12 Completed 302 Found in 207ms -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
did not quite look into it. But i strongly suspect this "(0.2ms) SELECT 1 FROM "scripts" WHERE "scripts"."startp" = 0.0 LIMIT 1" This will return true/1 in any condition. -- rubyonrailsx Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Friday, March 16, 2012 at 1:40 PM, Soichi Ishida wrote:> Looking at the log... > The first one is successful in creating the first Script, the second > one is not. > SQL is not working for the second but certainly after_save method is > called..(''first script action HERE!!!!!!'' is logger.info (http://logger.info)). > > Does it help? > > soichi > > > > Started POST "/videos" for 127.0.0.1 at 2012-03-16 14:08:42 +0900 > Processing by VideosController#create as HTML > Parameters: {"utf8"=>"✓", > "authenticity_token"=>"/AYk7ocjjteBKH8fDpQZ7FKzme/0nSsT2kalq8FgI18=", > "video"=>{"title"=>"Rush Limbaugh Calls a Female Georgetown Student, > Sandra Fluke, a ''Slut''", > "url"=>"http://www.youtube.com/watch?v=3KNpn-XGM04", "language"=>"1", > "genre"=>"news"}, "commit"=>"Create Video"} > User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = > 1 LIMIT 1 > SQL (0.7ms) INSERT INTO "videos" ("created_at", "genre", "language", > "title", "updated_at", "url", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?) > [["created_at", Fri, 16 Mar 2012 14:08:43 JST +09:00], ["genre", > "news"], ["language", "1"], ["title", "Rush Limbaugh Calls a Female > Georgetown Student, Sandra Fluke, a ''Slut''"], ["updated_at", Fri, 16 Mar > 2012 14:08:43 JST +09:00], ["url", > "http://www.youtube.com/watch?v=3KNpn-XGM04"], ["user_id", 1]] > first script action HERE!!!!!! > (0.2ms) SELECT 1 FROM "scripts" WHERE "scripts"."startp" = 0.0 LIMIT > 1 > SQL (0.5ms) INSERT INTO "scripts" ("created_at", "startp", "text", > "updated_at", "video_id") VALUES (?, ?, ?, ?, ?) [["created_at", Fri, > 16 Mar 2012 14:08:43 JST +09:00], ["startp", > #<BigDecimal:102b7cd18,''0.0'',9(36)>], ["text", "ToDo: "], ["updated_at", > Fri, 16 Mar 2012 14:08:43 JST +09:00], ["video_id", 11]] > Redirected to http://localhost:3001/videos/11 > Completed 302 Found in 211ms > > > > > Started POST "/videos" for 127.0.0.1 at 2012-03-16 14:08:59 +0900 > Processing by VideosController#create as HTML > Parameters: {"utf8"=>"✓", > "authenticity_token"=>"/AYk7ocjjteBKH8fDpQZ7FKzme/0nSsT2kalq8FgI18=", > "video"=>{"title"=>"bergman trailer persona", > "url"=>"http://www.youtube.com/watch?v=XZsU_ACYSAA", "language"=>"1", > "genre"=>"persona"}, "commit"=>"Create Video"} > User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = > 1 LIMIT 1 > SQL (0.7ms) INSERT INTO "videos" ("created_at", "genre", "language", > "title", "updated_at", "url", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?) > [["created_at", Fri, 16 Mar 2012 14:09:00 JST +09:00], ["genre", > "persona"], ["language", "1"], ["title", "bergman trailer persona"], > ["updated_at", Fri, 16 Mar 2012 14:09:00 JST +09:00], ["url", > "http://www.youtube.com/watch?v=XZsU_ACYSAA"], ["user_id", 1]] > first script action HERE!!!!!! > (0.2ms) SELECT 1 FROM "scripts" WHERE "scripts"."startp" = 0.0 LIMIT > 1 > Redirected to http://localhost:3001/videos/12 > Completed 302 Found in 207ms > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I found the mistake in my code. I have put one of the fields of Script, startp, to become ":uniquness => true". I didn''t know that it is effective for all sets of Script instances that belong to a single Video. Anyway, thanks for your answers. 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 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.