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"