Skip to content

Instantly share code, notes, and snippets.

@keating
Last active December 10, 2015 12:28
Show Gist options
  • Save keating/4434326 to your computer and use it in GitHub Desktop.
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.
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
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