【问题标题】:How a code can be assigned to an Application custom error messages如何将代码分配给应用程序自定义错误消息
【发布时间】:2013-07-29 10:43:32
【问题描述】:

如何在 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"                 

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 rubygems rails-i18n i18n-gem


    【解决方案1】:

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

    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"
    

    使用代码而不是名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-19
      • 2013-11-12
      • 1970-01-01
      • 2011-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多