Last active
December 10, 2015 12:28
-
-
Save keating/4434326 to your computer and use it in GitHub Desktop.
You can use the 't' method with `I18n.t` in models. And the first parameter of the 'add' method here should be empty string for not be reduplicate.
A new method is not necessary, see the second file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validate :start_date_validate | |
def start_date_validate | |
if start_date && end_date | |
if start_date >= end_date | |
errors.add("", I18n.t("education_information.start_end_not_validate")) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validate do | |
profiles = Profile.where(:first_name => first_name, :last_name => last_name) | |
unless profiles.empty? | |
if self.new_record? | |
errors.add("", "First name and last name already exist at the same time") | |
else | |
errors.add("", "First name and last name already exist at the same time") if (profiles.first.id != self.id) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment