Module: ShowFor::Helper

Defined in:
lib/show_for/helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) show_for(object, html_options = {}, &block)

Creates a div around the object and yields a builder.

Example:

show_for @user do |f|
  f.attribute :name
  f.attribute :email
end


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/show_for/helper.rb', line 12

def show_for(object, html_options={}, &block)
  tag = html_options.delete(:show_for_tag) || ShowFor.show_for_tag

  html_options[:id]  ||= dom_id(object)
  html_options[:class] = "show_for #{dom_class(object)} #{html_options[:class]}".rstrip

  builder = html_options.delete(:builder) || ShowFor::Builder
  content = capture(builder.new(object, self), &block)

  (tag, content, html_options)
end