Rails custom validation

后端 未结 1 1294
梦毁少年i
梦毁少年i 2020-12-16 18:25

I have a user signup form that has the usual fields (name, email, password, etc...) and also a \"team_invite_code\" field and a \"role\" popup menu.

Before creating

相关标签:
1条回答
  • 2020-12-16 18:46

    Your validate method child_and_team_code_exists should be a private or protected method, otherwise in your case it becomes an instance method

    validate :child_and_team_code_exists
    
    
    private
    def child_and_team_code_exists
       errors.add(:team_code, t("user_form.team_code_not_present")) unless
       self.is_child? && Team.scoped_by_code("params[:team_code]").exists?
    end
    
    0 讨论(0)
提交回复
热议问题