0

如何在 Ruby on Rails 中为应用程序自定义错误消息提供代码。当用户看到错误时,他应该能够知道错误代码和消息。

例如,我想达到以下结果,以防出现相应的错误。

CODE  Message    
4081  You are not allowed to view the private document 
5082  Company with this name already present
5034  Page removed

这是一个多语言应用程序。/config/locales/en.yml 中存在错误消息的翻译。我正在使用 i18n gem 进行翻译。这就是没有代码的错误消息的翻译方式。

errors:
  messages:
    private_document: "You are not allowed to view the private document" 
    company_name: "Company with this name already present" 
    page_remove: "Page removed"                 
4

1 回答 1

0

你在找这样的东西吗?......

errors:
  messages:
    4081 "You are not allowed to view the private document" 
    5082 "Company with this name already present" 
    5034 "Bidding end date should be greater than current date and time"

使用代码而不是名称。

于 2013-07-29T11:32:34.503 回答