I have an after_save callback setup, but it''s getting called twice. Per https://rails.lighthouseapp.com/projects/8994/tickets/764-observers-on-a-model-are-called-multiple-times , this is a known issue that won''t be fixed. (In summary, rails doesn''t convert required files to absolute paths, so files get required twice, and their callbacks are registered twice.) The fixes that are offered just haven''t worked for me, and I don''t know why. Can anyone offer any sort of solution or work around? Thanks! -- 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 Aug 30, 3:30 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have an after_save callback setup, but it''s getting called twice. > Perhttps://rails.lighthouseapp.com/projects/8994/tickets/764-observers-o... > , this is a known issue that won''t be fixed. (In summary, rails > doesn''t convert required files to absolute paths, so files get > required twice, and their callbacks are registered twice.) The fixes > that are offered just haven''t worked for me, and I don''t know why. > > Can anyone offer any sort of solution or work around?Why are you requiring the file with different paths in multiple places? Fred> > Thanks!-- 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''m not, rails is. On Aug 30, 11:00 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Aug 30, 3:30 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have an after_save callback setup, but it''s getting called twice. > > Perhttps://rails.lighthouseapp.com/projects/8994/tickets/764-observers-o... > > , this is a known issue that won''t be fixed. (In summary, rails > > doesn''t convert required files to absolute paths, so files get > > required twice, and their callbacks are registered twice.) The fixes > > that are offered just haven''t worked for me, and I don''t know why. > > > Can anyone offer any sort of solution or work around? > > Why are you requiring the file with different paths in multiple > places? > > Fred > > > > > > > > > > > Thanks!-- 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 Aug 30, 4:13 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m not, rails is. >you''re going to have to explain a little more about how this is arising if you want anyone to be able to give concrete advice. Fred> On Aug 30, 11:00 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On Aug 30, 3:30 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have an after_save callback setup, but it''s getting called twice. > > > Perhttps://rails.lighthouseapp.com/projects/8994/tickets/764-observers-o... > > > , this is a known issue that won''t be fixed. (In summary, rails > > > doesn''t convert required files to absolute paths, so files get > > > required twice, and their callbacks are registered twice.) The fixes > > > that are offered just haven''t worked for me, and I don''t know why. > > > > Can anyone offer any sort of solution or work around? > > > Why are you requiring the file with different paths in multiple > > places? > > > Fred > > > > Thanks!-- 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.
First - in the subject I said "after_save" but meant "after_create" but the issue is the same. I think I may have just figured it out, but perhaps you could verify. I have a project model and events models. When I create a project, I loop through an array that creates default events. I noticed that all the events were getting created twice. Here''s the Project model: class Project < ActiveRecord::Base has_many :events after_create :after_create def after_create ## create my default events end end The problem, I think, is that after_create is called automatically, and you only need to have the "after_create :after_create" line if the callback is named something besides callback event. Once I took out the "after_create :after_create" line, it seemed to work. I didn''t try it, but I suppose I could have left it in but named the method something besides "after_create" like "add_default_events." So is what I have said correct? Thanks for taking the time to help me with this. On Aug 30, 12:26 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Aug 30, 4:13 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m not, rails is. > > you''re going to have to explain a little more about how this is > arising if you want anyone to be able to give concrete advice. > > Fred > > > > > > > > > On Aug 30, 11:00 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On Aug 30, 3:30 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have an after_save callback setup, but it''s getting called twice. > > > > Perhttps://rails.lighthouseapp.com/projects/8994/tickets/764-observers-o... > > > > , this is a known issue that won''t be fixed. (In summary, rails > > > > doesn''t convert required files to absolute paths, so files get > > > > required twice, and their callbacks are registered twice.) The fixes > > > > that are offered just haven''t worked for me, and I don''t know why. > > > > > Can anyone offer any sort of solution or work around? > > > > Why are you requiring the file with different paths in multiple > > > places? > > > > Fred > > > > > Thanks!-- 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 30 August 2010 17:39, richardsugg <richardsugg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> First - in the subject I said "after_save" but meant "after_create" > but the issue is the same. I think I may have just figured it out, > but perhaps you could verify. I have a project model and events > models. When I create a project, I loop through an array that creates > default events. I noticed that all the events were getting created > twice. Here''s the Project model: > > class Project < ActiveRecord::Base > has_many :events > after_create :after_create > > def after_create > ## create my default events > end > end > > The problem, I think, is that after_create is called automatically, > and you only need to have the "after_create :after_create" line if the > callback is named something besides callback event. Once I took out > the "after_create :after_create" line, it seemed to work. I didn''t > try it, but I suppose I could have left it in but named the method > something besides "after_create" like "add_default_events." > > So is what I have said correct?Yes, that''s correct. It was being called twice because you had defined the ''after_create'' method, which gets called automatically, *and* you had added your ''after_create'' method to the after_create callback chain by calling ''after_create :after_create''. Chris -- 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.
okey doke -- thanks for the confirmation. On Aug 31, 5:04 am, Chris Mear <chrism...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 30 August 2010 17:39, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > First - in the subject I said "after_save" but meant "after_create" > > but the issue is the same. I think I may have just figured it out, > > but perhaps you could verify. I have a project model and events > > models. When I create a project, I loop through an array that creates > > default events. I noticed that all the events were getting created > > twice. Here''s the Project model: > > > class Project < ActiveRecord::Base > > has_many :events > > after_create :after_create > > > def after_create > > ## create my default events > > end > > end > > > The problem, I think, is that after_create is called automatically, > > and you only need to have the "after_create :after_create" line if the > > callback is named something besides callback event. Once I took out > > the "after_create :after_create" line, it seemed to work. I didn''t > > try it, but I suppose I could have left it in but named the method > > something besides "after_create" like "add_default_events." > > > So is what I have said correct? > > Yes, that''s correct. It was being called twice because you had defined > the ''after_create'' method, which gets called automatically, *and* you > had added your ''after_create'' method to the after_create callback > chain by calling ''after_create :after_create''. > > Chris-- 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.