Manuel Moreno
Manuel Moreno

Reputation: 39

Is it possible to write a success message with locales?

Same way as error messages can be customized and called on the html, can a success message be called on the html once a form is saved through locales?

Upvotes: 0

Views: 39

Answers (1)

retgoat
retgoat

Reputation: 2464

Yes, sure. Consider this:

# 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 You can add any message type you want: success, terrible_error, foo_bar to the flash object.

Upvotes: 1

Related Questions