Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails translate custom base error

My models:

Product has_many variants has_many sizes

To sizes I add custom error, like this:

errors.add :base, "My custom error msg"

In the view I see: "Sizes base My custom error msg"

class Size < ActiveRecord::Base
  ...
  validate :custom_error, only: :update
  ...
  def custom_error
    errors.add :base, "My custom error msg"
  end
end

But how translate this message?

UPDATED I am found solution:

In locale.yml:

attributes:
  variants/sizes:
    base: ''
like image 688
zolter Avatar asked Jan 10 '14 18:01

zolter


Video Answer


1 Answers

Try:

errors.add :base, :custom_error

This should give you translation missing together with key name and a scope where this translation should be stored.

Update:

Just did it by myself:

translation missing: [locale].activerecord.errors.models.[model_name].attributes.base.custom_error
like image 81
BroiSatse Avatar answered Oct 17 '22 15:10

BroiSatse