Last active
October 30, 2015 11:18
-
-
Save berkes/cce1cae0e6a1f08f3582 to your computer and use it in GitHub Desktop.
Rails helper to render the errors or a form as flash messages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flash_errors_for(model) | |
return unless model.errors.any? | |
messages = [I18n.t("errors.messages.not_saved", | |
count: model.errors.size, | |
resource: model.model_name)] | |
# Sanitize any errors | |
messages << model.errors.to_a.map(&:html_safe) | |
# assign to alert, mark as safe | |
flash.now.alert = messages.join("<br/>").html_safe | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2><%= t("forgot_password") %></h2> | |
<%- flash_errors_for(@pw_reset_instructions) %> | |
<%= simple_form_for(@pw_reset_instructions, | |
as: :user, | |
url: passwords_path) do |f| %> | |
<%= f.input :email %> | |
<%= f.button :submit, t("send_password_instructions") %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment