class Aerogel::Forms::FormBuilder

Constants

DEFAULT_OPTIONS

Attributes

content[RW]
options[RW]

Public Class Methods

new( object, options, &block ) click to toggle source
Calls superclass method
# File lib/aerogel/forms/form_builder.rb, line 16
def initialize( object, options, &block )
  super( object, nil, nil, options, &block )
  @hiddens = []
  @options = DEFAULT_OPTIONS.dup.deep_merge( options )
  @options[:cancel_url] ||= back
  hidden csrf_field_name, csrf_token if csrf_protected?
  hidden :id, object.id if object.respond_to? :id
end

Public Instance Methods

button( type = :submit, options = {} ) click to toggle source

Renders button

# File lib/aerogel/forms/form_builder.rb, line 32
def button( type = :submit, options = {} )
  b = FormButton.new self, type, options
  erb template( :button ), locals: { button: b, type: b.type, options: b.options, form_builder: self }, layout: false
end
buttons( *args ) click to toggle source

Renders a list of buttons

# File lib/aerogel/forms/form_builder.rb, line 39
def buttons( *args )
  args = [:cancel, :submit] if args.size == 0
  output = ''
  args.each do |b|
    output += button b
  end
  output
end
hidden( name, value ) click to toggle source
# File lib/aerogel/forms/form_builder.rb, line 25
def hidden( name, value )
  @hiddens << { name: name, value: value }
  nil
end
html_params() click to toggle source

Returns a Hash with <form ..> tag attributes.

# File lib/aerogel/forms/form_builder.rb, line 57
def html_params
  attrs = @options[:html_params].dup
  attrs.merge!({
    :method => @options[:method],
    # :action => @options[:action]
  })
  attrs[:action] = @options[:action] if @options[:action]
  attrs[:enctype] = 'multipart/form-data' if @options[:multipart]
  attrs.map{|n, v| v.nil? ? "#{n}" : "#{n}=\"#{v}\""}.join(" ")
end
render_hiddens() click to toggle source
# File lib/aerogel/forms/form_builder.rb, line 68
def render_hiddens
  @hiddens.map{|hidden| (input_hidden_tag hidden[:name], hidden[:value])+"\n" }.join()
end
wrap( content ) click to toggle source
# File lib/aerogel/forms/form_builder.rb, line 48
def wrap( content )
  erb :"form_builder/#{@style}/form", locals: { form: self, content: content }, layout: false
  # self.instance_exec( self, &STYLES[@style][:form_decorator] )
end