Skip to content

Instantly share code, notes, and snippets.

@qw3r
Created March 24, 2012 20:07
Show Gist options
  • Save qw3r/2187397 to your computer and use it in GitHub Desktop.
Save qw3r/2187397 to your computer and use it in GitHub Desktop.
simple way to show form as description list using twitter bootstrap
module ApplicationHelper
def definition_lists_for(model, &block)
dl = DefinitionListHelper.new model
yield dl
end
class DefinitionListHelper
include ActionView::Helpers
include ActionView::Context
include Haml::Helpers
attr_accessor :model
def initialize(model)
self.model = model
init_haml_helpers
end
def inputs(legend = nil, options = {}, &block)
ret = ''
ret << content_tag(:fieldset, options) do
ret2 = ''
ret2 << content_tag(:legend, legend) unless legend.nil?
ret2 << content_tag(:dl, capture(&block), class: 'dl-horizontal')
ret2.html_safe
end
ret.html_safe
end
def text_field(*args)
item *args
end
def email_field(*args)
item *args
end
def item(method, title = nil)
ret = ''
ret << content_tag(:dt, title) unless title.blank?
ret << content_tag(:dd, method.is_a?(Symbol) ? @model.send(method) : method)
ret.html_safe
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment