Skip to content

Instantly share code, notes, and snippets.

@gnepud
Created February 9, 2012 14:40
Show Gist options
  • Save gnepud/1780422 to your computer and use it in GitHub Desktop.
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
<% 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 %>
# 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