Where are Default Validation Error Messages in Rails 3.0?

后端 未结 1 1814
别跟我提以往
别跟我提以往 2021-01-04 01:15

Where are the default validation error messages in Rails 3.0? What is the equivalent of ActiveRecord::Error.default_error_messages[:taken], for example? I have gotten as far

相关标签:
1条回答
  • 2021-01-04 01:35

    http://github.com/rails/rails/blob/master/activemodel/lib/active_model/locale/en.yml

    and

    http://github.com/rails/rails/blob/master/activerecord/lib/active_record/locale/en.yml

    :D

    UPDATE:

    Maybe you should try to add your own custom error messages?

    # de.yml
    activerecord:
      errors:
        messages:
          taken: "ist bereits vergeben"
    
    # test_spec.rb
    ...
    assert_equal(object.errors[field], I18n.t("activerecord.errors.messages.taken"))
    ...
    
    0 讨论(0)
提交回复
热议问题