Top Level Namespace

Defined Under Namespace

Modules: AtMost

Instance Method Summary collapse

Instance Method Details

#downcase_and_pluralize(input) ⇒ Object



4
5
6
# File 'lib/at_most.rb', line 4

def downcase_and_pluralize(input)
  return "#{ input.to_s.downcase }s"
end

#i18n_error(model) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/at_most.rb', line 12

def i18n_error(model)
  if !I18n.t("activerecord.errors.models.#{ downcase_and_pluralize(model.class) }.at_most").include?("missing")
    I18n.t("activerecord.errors.models.#{ downcase_and_pluralize(model.class) }.at_most")
  elsif !I18n.t("at_most").include?("missing")
    I18n.t("at_most")
  end
end

#validation_error(model, message) ⇒ Object



8
9
10
# File 'lib/at_most.rb', line 8

def validation_error(model, message)
  message || i18n_error(model) || "Maximum number of #{model.class}s has been reached"
end