Skip to content

Instantly share code, notes, and snippets.

@nalanj
Forked from trosage/gist:1386386
Created November 22, 2011 18:06
Show Gist options
  • Save nalanj/1386388 to your computer and use it in GitHub Desktop.
Save nalanj/1386388 to your computer and use it in GitHub Desktop.
def form_div(form, field, message = nil, options = {}, &block)
style_class = options[:class] || ""
style_class += " error" if form.object.errors[field].any?
div_options = {}
div_options[:class] = style_class unless style_class.blank?
buffer = ""
buffer << content_tag("div", div_options) do
inner_buffer = yield
unless message.nil?
inner_buffer << content_tag("span", :class => "tooltip tooltip-right", :style => "display: none;") do
buf = content_tag("span", message, :class => "note")
buf << content_tag("span", "", :class => "icon icon-tooltip-carrot")
buf
end
end
if form.object.errors[field].any?
inner_buffer << content_tag("p", form.object.errors[field].first, :class => "error-message")
end
inner_buffer
end
raw(buffer)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment