I just upgraded my application from Rails 2.3 to 3 and I’m getting some
DEPRECATION WARNINGS for my before_create ,update, save, destroy etc.
Does anyone know how ot fix the issue?
These are my Warnings :
DEPRECATION WARNING: Base#before_create has been deprecated, please use Base.before_create :method instead. (called from /Users/macmini/qna/app/models/user.rb:32)
DEPRECATION WARNING: Base#before_update has been deprecated, please use Base.before_update :method instead. (called from /Users/macmini/qna/app/models/user.rb:40)
DEPRECATION WARNING: Base#after_save has been deprecated, please use Base.after_save :method instead. (called from /Users/macmini/qna/app/models/user.rb:50)
DEPRECATION WARNING: Base#before_destroy has been deprecated, please use Base.before_destroy :method instead. (called from /Users/macmini/qna/app/models/user.rb:56)
Just one example for the before_create :
def before_create
self.username.downcase!
self.salt = User.make_salt(self.username)
self.hashed_password = User.hash_with_salt(@password, self.salt)
end
The warning you’re seeing is Rails 3’s attempt to discourage you from overwriting the base
before_*andafter_*methods. This is similar to how you would havebefore_filterand other callbacks in your controller.What this means is that instead of doing:
Rails wants you to do:
In this case, you might even split up the two, as there could be a possibility that you’d want to generate a password independently: