Last active
August 29, 2015 14:04
-
-
Save waldofe/83e7d18569c82678b838 to your computer and use it in GitHub Desktop.
Simple alert error message helper
This file contains 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 ApplicationHelper | |
# Renders the first field error of an object attribute on a red alert. | |
# | |
# @param klass [Class Object] - This object needs to | |
# include ActiveModel::Validations (or be a normal ActiveModel) | |
# @param field_sym [Symbol] - Attribute or field name of the object | |
def show_error_message_for(klass, attribute) | |
if klass.errors[attribute].any? | |
%( | |
<div class="alert alert-danger"> | |
#{klass.errors.full_messages_for(attribute).first} | |
</div> | |
).html_safe | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment