Skip to content

Instantly share code, notes, and snippets.

@trosage
Created November 22, 2011 18:03
Show Gist options
  • Save trosage/1386386 to your computer and use it in GitHub Desktop.
Save trosage/1386386 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
inner_buffer
end
if form.object.errors[field].any?
buffer << content_tag("p", form.object.errors[field].first, :class => "error-message")
end
raw(buffer)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment