Skip to content

Instantly share code, notes, and snippets.

@sahidursuman
Forked from yelps/application_helper.rb
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save sahidursuman/cf2e4e555296d2b44dad to your computer and use it in GitHub Desktop.

Select an option

Save sahidursuman/cf2e4e555296d2b44dad to your computer and use it in GitHub Desktop.
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