Skip to content

Instantly share code, notes, and snippets.

@willywg
Forked from seyhunak/devise_helper.rb
Last active November 5, 2016 15:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willywg/68e225b32897f2ea84caeb5131dc2cb2 to your computer and use it in GitHub Desktop.
Save willywg/68e225b32897f2ea84caeb5131dc2cb2 to your computer and use it in GitHub Desktop.
Devise Error Messages with Bootstrap 3 style
# /app/helpers/devise_helper.rb
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">
<button type="button" class="close" data-dismiss="alert">x</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