Created
October 29, 2015 21:56
-
-
Save pottedmeat7/3a7ee4815ca90934457a to your computer and use it in GitHub Desktop.
devise helper to list errors in alert box
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
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