Skip to content

Instantly share code, notes, and snippets.

@pottedmeat7
Created October 29, 2015 21:56
Show Gist options
  • Save pottedmeat7/3a7ee4815ca90934457a to your computer and use it in GitHub Desktop.
Save pottedmeat7/3a7ee4815ca90934457a to your computer and use it in GitHub Desktop.
devise helper to list errors in alert box
module DeviseHelper
def devise_error_messages!
return "" if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg|
content_tag :li do
content_tag(:div, ' ', :class=>'glyphicon glyphicon-exclamation-sign') +
content_tag(:span, ' '+msg)
end
}.join
sentence = I18n.t("errors.messages.not_saved",
:count => resource.errors.count,
:resource => resource.class.model_name.human.downcase)
html = <<-HTML
<div>
<ul class='alert alert-danger'>#{messages}</ul>
</div>
HTML
html.html_safe
end
def devise_error_messages?
resource.errors.empty? ? false : true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment