是否可以使用语言环境编写成功消息?
答
是的,当然。试想一下:
# views/layouts/application.html.erb
<% flash.each do |name, msg| -%>
<%= content_tag :div, msg, class: name %>
<% end -%>
# app/controllers/index_controller.rb
def index
flash[:notice] = t("Some notice")
flash[:a_terrible_error] = t("Some terrible error occured")
end
# config/locales/en.yml
en:
"Some notice": "Some Translated Notice"
"Some terrible error occured": "Some translated terrible error occured"