如何在spree模型user.rb中覆盖set_login?

时间:2016-08-22 10:54:47

标签: ruby-on-rails api model spree

在spree sign_up中app/models/spree/user.rb

def set_login
  # for now force login to be same as email, eventually we will make this configurable, etc.
  self.login ||= self.email if self.email
end

如何覆盖set login并执行以下操作:

def set_login
  # for now force login to be same as email, eventually we will make this configurable, etc.
  self.login ||= self.phone if self.phone
end

提前致谢

1 个答案:

答案 0 :(得分:0)

我是在app / models / spree / user_decorator.rb

中完成的
 Spree::User.class_eval do
    Spree::PermittedAttributes.user_attributes << :phone


 def set_login
   # for now force login to be same as email, eventually we will make this configurable, etc.
   self.login ||= self.phone if self.phone
 end
end