Method: Padrino::Helpers::FormHelpers#form_for

Defined in:
padrino-helpers/lib/padrino-helpers/form_helpers.rb

#form_for(object, url, options = {}, &block) {|AbstractFormBuilder| ... } ⇒ String

Constructs a form for object using given or default form_builder.

Examples:

form_for :user, '/register' do |f| ... end
form_for @user, '/register', :id => 'register' do |f| ... end
form_for @user, '/register', :as => :customer do |f| ... end

Parameters:

  • object (Object)

    The object for which the form is being built.

  • URL (String)

    The url this form will submit to.

  • options (Hash) (defaults to: {})

    The settings associated with this form. Accepts a :namespace option that will be prepended to the id attributes of the form's elements. Also accepts HTML options.

  • block (Proc)

    The fields and content inside this form.

  • settings (Hash)

    a customizable set of options

Yields:

  • (AbstractFormBuilder)

    The form builder used to compose fields.

Returns:

  • (String)

    The html object-backed form with the specified options and input fields.



44
45
46
47
48
49
50
# File 'padrino-helpers/lib/padrino-helpers/form_helpers.rb', line 44

def form_for(object, url, options={}, &block)
  instance = builder_instance(object, options)
  # this can erect instance.multipart flag if the block calls instance.file_field
  html = capture_html(instance, &block)
  options = { :multipart => instance.multipart }.update(options.reject{ |key,_| [:namespace, :as].include?(key) })
  form_tag(url, options) { html }
end