Skip to content

Instantly share code, notes, and snippets.

@dacur
Created February 28, 2015 16:21
Show Gist options
  • Save dacur/d87a84b779de30af3d0c to your computer and use it in GitHub Desktop.
Save dacur/d87a84b779de30af3d0c to your computer and use it in GitHub Desktop.
This helper file will add bootstrap styling to your devise error messages, and will make them more readable. Add this file to your helper files folder.
module DeviseHelper
def devise_error_messages!
return '' if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t('errors.messages.not_saved', count: resource.errors.count, resource: resource.class.model_name.human.downcase)
html = <<-HTML
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<h4>#{sentence}</h4>
#{messages}
</div>
HTML
html.html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment