Last active
August 29, 2015 14:05
-
-
Save CyberStrike/ad181d48025f5f4b0f41 to your computer and use it in GitHub Desktop.
Form Field Errors Rails 4
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
= error_message_for(:resource, :field_name, :prepend_text => '') |
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 ApplicationHelper | |
# Error messages for the specific form field | |
def error_message_for(resource, field, options = {:prepend_text => false}) | |
error_message = resource.errors[field] | |
# If the error messages are not empty put the error messages | |
# and the prepended text unless it's empty then put the field name. | |
unless error_message.empty? | |
"#{options[:prepend_text] || field.to_s.capitalize} #{error_message.to_s}".delete! '[]""' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment