是否可以使用区域设置编写成功消息?

时间:2016-07-28 21:54:56

标签: ruby-on-rails locale

可以在html上自定义和调用错误消息的方式相同,一旦通过区域设置保存表单,是否可以在html上调用成功消息?

1 个答案:

答案 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"

enter image description here 您可以向success对象添加所需的任何消息类型:terrible_errorfoo_barflash