Skip to content

Instantly share code, notes, and snippets.

@yelps
Created March 11, 2012 19:32
Show Gist options
  • Select an option

  • Save yelps/2017785 to your computer and use it in GitHub Desktop.

Select an option

Save yelps/2017785 to your computer and use it in GitHub Desktop.
Rails:Devise: customize display of field with errors
def field_with_errors(object, method, &block)
if block_given?
if object.errors[method].empty?
content = with_output_buffer(&block)
content.html_safe
else
content = with_output_buffer(&block)
content_tag(:span, content, :class => "field_with_errors")
end
end
end
def textarea_with_errors(object, method, &block)
if block_given?
if object.errors[method].empty?
content = with_output_buffer(&block)
content.html_safe
else
content = with_output_buffer(&block)
content = content.gsub(/class=\"#{method}_box\"/, "class=\"#{method}_box textarea_with_errors\"")
content.html_safe
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment