Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@berkes
Last active October 30, 2015 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berkes/cce1cae0e6a1f08f3582 to your computer and use it in GitHub Desktop.
Save berkes/cce1cae0e6a1f08f3582 to your computer and use it in GitHub Desktop.
Rails helper to render the errors or a form as flash messages.
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
<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