-1

如果我这样编码,我会收到语法错误。
我该如何解决?

before_save :handle_invitation_code, if: :just_confirmed

def just_confirmed?
  confirmed_at_changed? && confirmed_at_was.nil?
end

def handle_invitation_code
  ...
end
4

1 回答 1

2

How about?

before_save :handle_invitation_code

def just_confirmed?
  confirmed_at_changed? && confirmed_at_was.nil?
end

def handle_invitation_code
  if self.just_confirmed?
  ...
  end
end

Or you would have to pass the code in just_confirmed? as a Proc to the before_save.

于 2013-02-08T17:02:43.643 回答