Reputation: 267320
Just going through the rails tutorial, and I noticed that the error messages are all hard coded in the controller actions etc.
What is the pattern to pull these from a localized resource file? (I'm on chapter 9 so far)
Upvotes: 0
Views: 329
Reputation: 16075
In your en.yml file or create a new file in config/locales/messages.en.yml add your hard-coded error messages from the controller
en:
errors:
messages:
not_found: "The record you searched doesn't exist"
update_failed: "Your updated operation failed"
To display this messages use
(t "errors.messages.not_found")
Upvotes: 2
Reputation: 68036
There's a whole another guide about that.
(don't know what tutorial you're using, but from my experience guides.rubyonrails.org provides the best Rails reference material on the web)
Upvotes: 1