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