I know there are some preset structures in i18n locale file so that Rails pulls values automatically. For example, if you want to set the default submit button text for new records:
# /config/locales/en.yml
en:
helpers:
submit:
create: "Create %{model}"
user:
create: "Sign Up"
With this set, in views the following will result:
# /app/views/things/new.html.erb
<%= f.submit %> #=> Renders a submit button reading "Create Thing"
# /app/views/users/new.html.erb
<%= f.submit %> #=> Renders a submit button reading "Sign Up"
So Rails uses a preset hierarchy for getting the submit button text for different models. (i.e., you don't have to tell it which i18n text to get when using f.submit
.) I've been trying to find a way to do this with flash notices and alerts. Is there a similar preset structure for specifying default flash messages?
I know you can specify your own arbitrary structures like the following:
# /config/locales/en.yml
en:
controllers:
user_accounts:
create:
flash:
notice: "User account was successfully created."
# /app/controllers/users_controller.rb
def create
...
redirect_to root_url, notice: t('controllers.user_accounts.create.flash.notice')
...
end
But it's tedious to specify the notice: t('controllers.user_accounts.create.flash.notice')
every time. Is there a way to do this so that the controller "just knows" when to grab and display the appropriate flash messages specified in the locale file? If so, what's the default YAML structure for these?