I recently upgraded one of my apps to rails 2.0.2 and creating a certain object didn''t work. After some debugging, I discovered this exception: undefined method `update_without_callbacks'' for #<Journal: 0x4fc7048> where Journal is my model and I have this callback in journal.rb: def after_save make_journal_name make_inbound_email self.update_without_callbacks end (See * below for more info) Also, I thought while I was debugging that at some point I saw an exception that said I was trying to call a private method, but I can no longer reproduce that. Anybody know what''s going on? * Basically, what goes on here is that after I create or update a journal I need to create a name and inbound e-mail for the journal that include the journal_id, so this has to happen in the after_save so that the journal_id is available. However, if I call self.save that creates an endless loop. See: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/cc9cb64ca0923147/75432648e1aeee27?lnk=gst for more info. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 5, 12:01 pm, Scott <scottpo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I recently upgraded one of my apps to rails 2.0.2 and creating a > certain object didn''t work. After some debugging, I discovered this > exception: > > undefined method `update_without_callbacks'' for #<Journal: > 0x4fc7048> > > where Journal is my model and I have this callback in journal.rb: > > def after_save > make_journal_name > make_inbound_email > self.update_without_callbacks > end > > (See * below for more info) > > Also, I thought while I was debugging that at some point I saw an > exception that said I was trying to call a private method, but I can > no longer reproduce that. > > Anybody know what''s going on? > > * Basically, what goes on here is that after I create or update a > journal I need to create a name and inbound e-mail for the journal > that include the journal_id, so this has to happen in the after_save > so that the journal_id is available. However, if I call self.save > that creates an endless loop. See:http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/... > for more info.It''s hard to tell without knowing more of what the make_journal_name and make_inbound_email methods do. If these methods are updating attributes of the journal, you should probably move the self.update_without_callbacks to these methods as a self.update_attribute(:attr, value) and call self.reload if necessary in your after_save callback. Otherwise, you could try self.save_without_validation (or self.save_with_validation(false)), but I don''t know if these will skip the after_save callback (I don''t think they will). --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Unfortunately, calling self.update_attribute creates an endless loop because #update_attribute callsback after_save. Here''s a very simple example I setup where I simply want to append the ID of an object to it''s title after it''s created or updated: class Movie < ActiveRecord::Base def after_save self.title = self.title + self.id.to_s self.update_without_callbacks end end and it throws this error: NoMethodError in MoviesController#update private method `update_without_callbacks'' called for #<Movie: 0x38b1084> at /ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ attribute_methods.rb:205:in `method_missing''. That code calls "super" which is what throws the error...I presume because it''s calling the method on ActiveRecord::Base. That being said, it seems that the access level of update_without_callbacks changed from 1.2.x to 2.x...is that a feature or a bug? On Mar 4, 10:39 pm, scarred_beyond_belief <m...-nZyiYgZf6O26c6uEtOJ/EA@public.gmane.org> wrote:> On Mar 5, 12:01 pm, Scott <scottpo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I recently upgraded one of my apps to rails 2.0.2 and creating a > > certain object didn''t work. After some debugging, I discovered this > > exception: > > > undefined method `update_without_callbacks'' for #<Journal: > > 0x4fc7048> > > > where Journal is my model and I have this callback in journal.rb: > > > def after_save > > make_journal_name > > make_inbound_email > > self.update_without_callbacks > > end > > > (See * below for more info) > > > Also, I thought while I was debugging that at some point I saw an > > exception that said I was trying to call a private method, but I can > > no longer reproduce that. > > > Anybody know what''s going on? > > > * Basically, what goes on here is that after I create or update a > > journal I need to create a name and inbound e-mail for the journal > > that include the journal_id, so this has to happen in the after_save > > so that the journal_id is available. However, if I call self.save > > that creates an endless loop. See:http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/... > > for more info. > > It''s hard to tell without knowing more of what the make_journal_name > and make_inbound_email methods do. If these methods are updating > attributes of the journal, you should probably move the > self.update_without_callbacks to these methods as a > self.update_attribute(:attr, value) and call self.reload if necessary > in your after_save callback. Otherwise, you could try > self.save_without_validation (or self.save_with_validation(false)), > but I don''t know if these will skip the after_save callback (I don''t > think they will).--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''ve been trying to figure out how the access level has changed, but I can''t see it directly. I do see one meaningful change to callbacks.rb that occurred on 8/31/07: http://dev.rubyonrails.org/changeset/7380. I don''t really understand the change very well...anyone? On Mar 4, 11:02 pm, Scott <scottpo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Unfortunately, calling self.update_attribute creates an endless loop > because #update_attribute callsback after_save. > > Here''s a very simple example I setup where I simply want to append the > ID of an object to it''s title after it''s created or updated: > > class Movie < ActiveRecord::Base > def after_save > self.title = self.title + self.id.to_s > self.update_without_callbacks > end > end > > and it throws this error: > > NoMethodError in MoviesController#update > private method `update_without_callbacks'' called for #<Movie: > 0x38b1084> > > at /ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > attribute_methods.rb:205:in `method_missing''. That code calls "super" > which is what throws the error...I presume because it''s calling the > method on ActiveRecord::Base. > > That being said, it seems that the access level of > update_without_callbacks changed from 1.2.x to 2.x...is that a feature > or a bug? > > On Mar 4, 10:39 pm, scarred_beyond_belief <m...-nZyiYgZf6O26c6uEtOJ/EA@public.gmane.org> wrote: > > > On Mar 5, 12:01 pm, Scott <scottpo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I recently upgraded one of my apps to rails 2.0.2 and creating a > > > certain object didn''t work. After some debugging, I discovered this > > > exception: > > > > undefined method `update_without_callbacks'' for #<Journal: > > > 0x4fc7048> > > > > where Journal is my model and I have this callback in journal.rb: > > > > def after_save > > > make_journal_name > > > make_inbound_email > > > self.update_without_callbacks > > > end > > > > (See * below for more info) > > > > Also, I thought while I was debugging that at some point I saw an > > > exception that said I was trying to call a private method, but I can > > > no longer reproduce that. > > > > Anybody know what''s going on? > > > > * Basically, what goes on here is that after I create or update a > > > journal I need to create a name and inbound e-mail for the journal > > > that include the journal_id, so this has to happen in the after_save > > > so that the journal_id is available. However, if I call self.save > > > that creates an endless loop. See:http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/... > > > for more info. > > > It''s hard to tell without knowing more of what the make_journal_name > > and make_inbound_email methods do. If these methods are updating > > attributes of the journal, you should probably move the > > self.update_without_callbacks to these methods as a > > self.update_attribute(:attr, value) and call self.reload if necessary > > in your after_save callback. Otherwise, you could try > > self.save_without_validation (or self.save_with_validation(false)), > > but I don''t know if these will skip the after_save callback (I don''t > > think they will).--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---