我想覆盖模型中的find_by_方法... 然后在里面我想调用原始+一些额外的代码。
class User < Activerecord::Base
def self.find_by_email(email)
binding.pry
super.find_by_email(email) || find_by_social_identities_email(email)
end
...
end
欢迎任何想法????
答案 0 :(得分:3)
最后我这样做了:
class User < Activerecord::Base
def self.find_by_email(email)
super.find_by('email = :email', {email: email}) || find_by_social_identities_email(email)
end
...
end
答案 1 :(得分:0)
对于Rails 5,我需要使用self
而不是super
。所以它变成了:
class User < ApplicationRecord
def self.find_by_email(email)
self.find_by('email = :email', {email: email}) || find_by_social_identities_email(email)
end
...
end