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.
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).
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?
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?