当我尝试u = User.new
后跟u.save
时,before_save
方法未被触发。
这是我的User
型号:
class User < ActiveRecord::Base
attr_accessor :password
before_save :encrypt_password
def encrypt_password
puts "Its getting called"
end
end
https://railsforum.com/topic/1741-rails-4-and-before-save-method/
答案 0 :(得分:15)
回调方法必须是protected
或private
。
从Types of callbacks