0

How a code can be given to an Application custom error messages in Ruby on Rails. when a user sees an error, he should be able to know both its error code and message.

For example, I want to achieve the following result, in case of respective error.

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

This is a multilingual application. Translations for error messages are present in /config/locales/en.yml. I'm using i18n gem for translation. This is how translation for error messages are present without code.

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"                 
kashif
  • 1,097
  • 4
  • 17
  • 32

1 Answers1

0

Something like this are you looking for?....

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"

Use code instead of name.

Thaha kp
  • 3,689
  • 1
  • 26
  • 25