Created
February 9, 2012 14:40
-
-
Save gnepud/1780422 to your computer and use it in GitHub Desktop.
Helper pour modifier un field de form quand il y a un erreur
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
<% field_with_errors @zonage, :name do %> | |
<div class="control-group"> | |
<%= f.label 'Nom du zonage', :class => 'control-label' %> | |
<div class="controls"> | |
<%= f.text_field :name %> | |
</div> | |
</div> | |
<% end %> |
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
# http://lukecarrier.me/2011/08/rails-3-0-select-tags-and-field_with_errors/ | |
# modified for replacer a class | |
def field_with_errors(object, method, &block) | |
if block_given? | |
if object.errors[method].empty? | |
concat capture(&block) | |
else | |
add_error = capture(&block).gsub("control-group", "control-group error") | |
concat raw(add_error) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment