可以在html上自定义和调用错误消息的方式相同,一旦通过区域设置保存表单,是否可以在html上调用成功消息?
答案 0 :(得分:1)
是的,当然。考虑一下:
# 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"