I''ve got something weird happening in the code (using Rails 3.0). I have a ton of has_many/belongs_to relationships in my application and I save the child objects like this: if parent.child_collection << child #do success code else #do error code end The problem is that this ends up with duplicate child records in the database, saved two seconds apart. The weird part is that this happens when the user is using IE or Chrome, but NOT when using Firefox. I''m wondering if this is Javascript related (I''m using jQuery), but I do get two "Success" messages in Firefox even though it only saves once. The #do success code uses Ajax to put up a view of the parent object with the children in a table. Should I explicitly save the child before I add it to the collection? This code seemed to work just fine before I "AJAX-ified" the application, but then I always use Firefox for development -- 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, Mar 10, 2011 at 3:00 PM, danm <dmuchnok-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve got something weird happening in the code (using Rails 3.0). I > have a ton of has_many/belongs_to relationships in my application and > I save the child objects like this: > > if parent.child_collection << child > #do success code > else > #do error code > end > > The problem is that this ends up with duplicate child records in the > database, saved two seconds apart. The weird part is that this > happens when the user is using IE or Chrome, but NOT when using > Firefox. I''m wondering if this is Javascript related (I''m using > jQuery), but I do get two "Success" messages in Firefox even though it > only saves once. The #do success code uses Ajax to put up a view of > the parent object with the children in a table. > >Without seeing some actual code it is hard to tell exactly what the issue is. I would, on the suffurace, guess that your AJAX code is submitting the same request twice since you are seeing 2 successes in the browser. Start there for debugging. B. -- 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 March 2011 21:00, danm <dmuchnok-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve got something weird happening in the code (using Rails 3.0). I > have a ton of has_many/belongs_to relationships in my application and > I save the child objects like this: > > if parent.child_collection << child > #do success code > else > #do error code > end > > The problem is that this ends up with duplicate child records in the > database, saved two seconds apart. The weird part is that this > happens when the user is using IE or Chrome, but NOT when using > Firefox. I''m wondering if this is Javascript related (I''m using > jQuery), but I do get two "Success" messages in Firefox even though it > only saves once. The #do success code uses Ajax to put up a view of > the parent object with the children in a table.Can you not see what is happening by carefully examining the log file (log/development.log)? For example if two requests were being made you should see that there. Another thought, have you validated the full page html in the w3c html validator? Differences between browsers is often a sign of malformed html. Also check in the firebug plugin in firefox that there are no javascript errors. Colin Colin> > Should I explicitly save the child before I add it to the collection? > This code seemed to work just fine before I "AJAX-ified" the > application, but then I always use Firefox for development > > -- > 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. > >-- 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.
Thanks for the tip about watching development.log, Colin. But now the mystery deepens. Using IE 8.0, EVERY AJAX call shows up twice. However, using the exact same links in Firefox 3.6.14, they only show up once. I am tailing the log file and watching it as I click on links in both browsers and I can see the duplicate entries going by in real time. It''s happening for GET, POST and DELETE requests in IE, but only the ones running through AJAX. The same requests in Firefox only run once. Interestingly, I''m not seeing the double success entries in Firefox any longer, but I just updated it this morning. Maybe I''m seeing something odd with the new jQuery implementation in 3.0? On Mar 10, 5:04 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 10 March 2011 21:00, danm <dmuch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''ve got something weird happening in the code (using Rails 3.0). I > > have a ton of has_many/belongs_to relationships in my application and > > I save the child objects like this: > > > if parent.child_collection << child > > #do success code > > else > > #do error code > > end > > > The problem is that this ends up with duplicate child records in the > > database, saved two seconds apart. The weird part is that this > > happens when the user is using IE or Chrome, but NOT when using > > Firefox. I''m wondering if this is Javascript related (I''m using > > jQuery), but I do get two "Success" messages in Firefox even though it > > only saves once. The #do success code uses Ajax to put up a view of > > the parent object with the children in a table. > > Can you not see what is happening by carefully examining the log file > (log/development.log)? For example if two requests were being made > you should see that there. > > Another thought, have you validated the full page html in the w3c html > validator? Differences between browsers is often a sign of malformed > html. Also check in the firebug plugin in firefox that there are no > javascript errors. > > Colin > > Colin > > > > > Should I explicitly save the child before I add it to the collection? > > This code seemed to work just fine before I "AJAX-ified" the > > application, but then I always use Firefox for development > > > -- > > 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 athttp://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.
On 11 March 2011 02:38, danm <dmuchnok-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the tip about watching development.log, Colin. But now the > mystery > deepens. Using IE 8.0, EVERY AJAX call shows up twice. However, > using the exact same links in Firefox 3.6.14, they only show up once. > I am > tailing the log file and watching it as I click on links in both > browsers and > I can see the duplicate entries going by in real time. It''s happening > for GET, > POST and DELETE requests in IE, but only the ones running through > AJAX. > The same requests in Firefox only run once. > > Interestingly, I''m not seeing the double success entries in Firefox > any > longer, but I just updated it this morning. Maybe I''m seeing > something > odd with the new jQuery implementation in 3.0?Did you check that html is valid and check the page with firebug enabled in firefox? Colin> > On Mar 10, 5:04 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 10 March 2011 21:00, danm <dmuch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> > I''ve got something weird happening in the code (using Rails 3.0). I >> > have a ton of has_many/belongs_to relationships in my application and >> > I save the child objects like this: >> >> > if parent.child_collection << child >> > #do success code >> > else >> > #do error code >> > end >> >> > The problem is that this ends up with duplicate child records in the >> > database, saved two seconds apart. The weird part is that this >> > happens when the user is using IE or Chrome, but NOT when using >> > Firefox. I''m wondering if this is Javascript related (I''m using >> > jQuery), but I do get two "Success" messages in Firefox even though it >> > only saves once. The #do success code uses Ajax to put up a view of >> > the parent object with the children in a table. >> >> Can you not see what is happening by carefully examining the log file >> (log/development.log)? For example if two requests were being made >> you should see that there. >> >> Another thought, have you validated the full page html in the w3c html >> validator? Differences between browsers is often a sign of malformed >> html. Also check in the firebug plugin in firefox that there are no >> javascript errors. >> >> Colin >> >> Colin >> >> >> >> > Should I explicitly save the child before I add it to the collection? >> > This code seemed to work just fine before I "AJAX-ified" the >> > application, but then I always use Firefox for development >> >> > -- >> > 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. >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://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. > >-- 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 do have firebug enabled in Firefox - it just wasn''t showing any issues. The W3C validator did the trick. It turns out that I was missing a single ">" on the end of a <table> tag. It was missing on the base page that I was refreshing over and over again with AJAX, so all of my AJAX calls were impacted by the same issue. I guess Firefox was just being clever and hiding the error, but the other browsers kept hitting the problem. Thanks for the great tip and I''ve bookmarked the W3C Validator page! Dan On Mar 11, 3:47 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 11 March 2011 02:38, danm <dmuch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Thanks for the tip about watching development.log, Colin. But now the > > mystery > > deepens. Using IE 8.0, EVERY AJAX call shows up twice. However, > > using the exact same links in Firefox 3.6.14, they only show up once. > > I am > > tailing the log file and watching it as I click on links in both > > browsers and > > I can see the duplicate entries going by in real time. It''s happening > > for GET, > > POST and DELETE requests in IE, but only the ones running through > > AJAX. > > The same requests in Firefox only run once. > > > Interestingly, I''m not seeing the double success entries in Firefox > > any > > longer, but I just updated it this morning. Maybe I''m seeing > > something > > odd with the new jQuery implementation in 3.0? > > Did you check that html is valid and check the page with firebug > enabled in firefox? > > Colin > > > > > On Mar 10, 5:04 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 10 March 2011 21:00, danm <dmuch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > I''ve got something weird happening in the code (using Rails 3.0). I > >> > have a ton of has_many/belongs_to relationships in my application and > >> > I save the child objects like this: > > >> > if parent.child_collection << child > >> > #do success code > >> > else > >> > #do error code > >> > end > > >> > The problem is that this ends up with duplicate child records in the > >> > database, saved two seconds apart. The weird part is that this > >> > happens when the user is using IE or Chrome, but NOT when using > >> > Firefox. I''m wondering if this is Javascript related (I''m using > >> > jQuery), but I do get two "Success" messages in Firefox even though it > >> > only saves once. The #do success code uses Ajax to put up a view of > >> > the parent object with the children in a table. > > >> Can you not see what is happening by carefully examining the log file > >> (log/development.log)? For example if two requests were being made > >> you should see that there. > > >> Another thought, have you validated the full page html in the w3c html > >> validator? Differences between browsers is often a sign of malformed > >> html. Also check in the firebug plugin in firefox that there are no > >> javascript errors. > > >> Colin > > >> Colin > > >> > Should I explicitly save the child before I add it to the collection? > >> > This code seemed to work just fine before I "AJAX-ified" the > >> > application, but then I always use Firefox for development > > >> > -- > >> > 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@googlegroups.com. > >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > For more options, visit this group athttp://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 athttp://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.