Class: ActionView::Helpers::FormBuilder

### Home Classes Methods

### In Files

- lib/action_view/helpers/date_helper.rb
- lib/action_view/helpers/form_helper.rb
- lib/action_view/helpers/form_options_helper.rb

### Parent

Object

### Methods

- ::_to_partial_path
- ::new
- #button
- #check_box
- #collection_select
- #date_select
- #datetime_select
- #emitted_hidden_id?
- #fields_for
- #file_field
- #grouped_collection_select
- #hidden_field
- #label
- #multipart=
- #radio_button
- #select
- #submit
- #time_select
- #time_zone_select
- #to_model
- #to_partial_path

### Class/Module Index

Quicksearch

- ActionDispatch
- ActionDispatch::Assertions
- ActionDispatch::Assertions::DomAssertions
- ActionDispatch::Assertions::ResponseAssertions
- ActionDispatch::Assertions::RoutingAssertions
- ActionDispatch::Assertions::SelectorAssertions
- ActionDispatch::Assertions::TagAssertions
- ActionDispatch::BestStandardsSupport
- ActionDispatch::BodyProxy
- ActionDispatch::Callbacks
- ActionDispatch::Cookies
- ActionDispatch::Cookies::CookieOverflow
- ActionDispatch::DebugExceptions
- ActionDispatch::ExceptionWrapper
- ActionDispatch::FileHandler
- ActionDispatch::Flash
- ActionDispatch::Flash::FlashHash
- ActionDispatch::Head
- ActionDispatch::Http
- ActionDispatch::Http::Cache
- ActionDispatch::Http::Cache::Request
- ActionDispatch::Http::Cache::Response
- ActionDispatch::Http::FilterParameters
- ActionDispatch::Http::Headers
- ActionDispatch::Http::MimeNegotiation
- ActionDispatch::Http::ParameterFilter
- ActionDispatch::Http::Parameters
- ActionDispatch::Http::URL
- ActionDispatch::Http::Upload
- ActionDispatch::Http::UploadedFile
- ActionDispatch::Integration
- ActionDispatch::Integration::RequestHelpers
- ActionDispatch::Integration::Runner
- ActionDispatch::Integration::Session
- ActionDispatch::IntegrationTest
- ActionDispatch::MiddlewareStack
- ActionDispatch::MiddlewareStack::Middleware
- ActionDispatch::ParamsParser
- ActionDispatch::PerformanceTest
- ActionDispatch::PublicExceptions
- ActionDispatch::RailsEntityStore
- ActionDispatch::RailsMetaStore
- ActionDispatch::Railtie
- ActionDispatch::Reloader
- ActionDispatch::RemoteIp
- ActionDispatch::RemoteIp::GetIp
- ActionDispatch::RemoteIp::IpSpoofAttackError
- ActionDispatch::Request
- ActionDispatch::RequestId
- ActionDispatch::Rescue
- ActionDispatch::Response
- ActionDispatch::Routing
- ActionDispatch::Routing::Mapper
- ActionDispatch::Routing::Mapper::Base
- ActionDispatch::Routing::Mapper::HttpHelpers
- ActionDispatch::Routing::Mapper::Resources
- ActionDispatch::Routing::Mapper::Scoping
- ActionDispatch::Routing::PolymorphicRoutes
- ActionDispatch::Routing::Redirection
- ActionDispatch::Routing::RouteSet
- ActionDispatch::Routing::RouteSet::MountedHelpers
- ActionDispatch::Routing::UrlFor
- ActionDispatch::Session
- ActionDispatch::Session::AbstractStore
- ActionDispatch::Session::CacheStore
- ActionDispatch::Session::Compatibility
- ActionDispatch::Session::CookieStore
- ActionDispatch::Session::DestroyableSession
- ActionDispatch::Session::MemCacheStore
- ActionDispatch::Session::StaleSessionCheck
- ActionDispatch::ShowExceptions
- ActionDispatch::Static
- ActionDispatch::TestProcess
- ActionDispatch::TestRequest
- ActionDispatch::TestResponse
- ActionController
- ActionController::Base
- ActionController::Caching
- ActionController::Caching::Actions
- ActionController::Caching::Actions::ActionCachePath
- ActionController::Caching::Actions::ClassMethods
- ActionController::Caching::ConfigMethods
- ActionController::Caching::Fragments
- ActionController::Caching::Pages
- ActionController::Caching::Pages::ClassMethods
- ActionController::Caching::Sweeping
- ActionController::Compatibility
- ActionController::ConditionalGet
- ActionController::Cookies
- ActionController::DataStreaming
- ActionController::Flash
- ActionController::ForceSSL
- ActionController::ForceSSL::ClassMethods
- ActionController::Head
- ActionController::Helpers
- ActionController::Helpers::ClassMethods
- ActionController::HideActions
- ActionController::HideActions::ClassMethods
- ActionController::HttpAuthentication
- ActionController::HttpAuthentication::Basic
- ActionController::HttpAuthentication::Basic::ControllerMethods
- ActionController::HttpAuthentication::Basic::ControllerMethods::ClassMethods
- ActionController::HttpAuthentication::Digest
- ActionController::HttpAuthentication::Digest::ControllerMethods
- ActionController::HttpAuthentication::Token
- ActionController::HttpAuthentication::Token::ControllerMethods
- ActionController::ImplicitRender
- ActionController::Instrumentation
- ActionController::Instrumentation::ClassMethods
- ActionController::LogSubscriber
- ActionController::Metal
- ActionController::Middleware
- ActionController::Middleware::ActionMiddleware
- ActionController::MimeResponds
- ActionController::MimeResponds::ClassMethods
- ActionController::ParamsWrapper
- ActionController::ParamsWrapper::ClassMethods
- ActionController::RackDelegation
- ActionController::Railtie
- ActionController::Railties
- ActionController::Railties::Paths
- ActionController::RecordIdentifier
- ActionController::Redirecting
- ActionController::Renderers
- ActionController::Renderers::All
- ActionController::Renderers::ClassMethods
- ActionController::Rendering
- ActionController::RequestForgeryProtection
- ActionController::RequestForgeryProtection::ClassMethods
- ActionController::Rescue
- ActionController::Responder
- ActionController::SessionManagement
- ActionController::SessionManagement::ClassMethods
- ActionController::Streaming
- ActionController::TemplateAssertions
- ActionController::TestCase
- ActionController::TestCase::Behavior
- ActionController::TestCase::Behavior::ClassMethods
- ActionController::TestCase::RaiseActionExceptions
- ActionController::TestResponse
- ActionController::Testing
- ActionController::Testing::ClassMethods
- ActionController::UrlFor
- ActionView
- ActionView::Base
- ActionView::Context
- ActionView::FileSystemResolver
- ActionView::FixtureResolver
- ActionView::Helpers
- ActionView::Helpers::ActiveModelHelper
- ActionView::Helpers::ActiveModelInstanceTag
- ActionView::Helpers::AssetPaths
- ActionView::Helpers::AssetTagHelper
- ActionView::Helpers::AssetTagHelper::AssetIncludeTag
- ActionView::Helpers::AssetTagHelper::JavascriptIncludeTag
- ActionView::Helpers::AssetTagHelper::JavascriptTagHelpers
- ActionView::Helpers::AssetTagHelper::JavascriptTagHelpers::ClassMethods
- ActionView::Helpers::AssetTagHelper::StylesheetIncludeTag
- ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers
- ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers::ClassMethods
- ActionView::Helpers::AtomFeedHelper
- ActionView::Helpers::AtomFeedHelper::AtomBuilder
- ActionView::Helpers::AtomFeedHelper::AtomFeedBuilder
- ActionView::Helpers::CacheHelper
- ActionView::Helpers::CaptureHelper
- ActionView::Helpers::CsrfHelper
- ActionView::Helpers::DateHelper
- ActionView::Helpers::DateHelperInstanceTag
- ActionView::Helpers::DebugHelper
- ActionView::Helpers::FormBuilder
- ActionView::Helpers::FormHelper
- ActionView::Helpers::FormOptionsHelper
- ActionView::Helpers::FormTagHelper
- ActionView::Helpers::InstanceTag
- ActionView::Helpers::JavaScriptHelper
- ActionView::Helpers::OutputSafetyHelper
- ActionView::Helpers::RecordTagHelper
- ActionView::Helpers::RenderingHelper
- ActionView::Helpers::SanitizeHelper
- ActionView::Helpers::TagHelper
- ActionView::Helpers::TextHelper
- ActionView::Helpers::TranslationHelper
- ActionView::Helpers::UrlHelper
- ActionView::LogSubscriber
- ActionView::LookupContext
- ActionView::LookupContext::DetailsCache
- ActionView::LookupContext::ViewPaths
- ActionView::NullResolver
- ActionView::PartialRenderer
- ActionView::Railtie
- ActionView::Renderer
- ActionView::Resolver
- ActionView::Resolver::Path
- ActionView::Template
- ActionView::Template::Handlers
- ActionView::Template::Handlers::Builder
- ActionView::Template::Handlers::ERB
- ActionView::Template::Handlers::Erubis
- ActionView::TestCase
- ActionView::TestCase::Behavior
- ActionView::TestCase::Behavior::ClassMethods
- ActionView::TestCase::Behavior::Locals
- ActionView::TestCase::TestController
- AbstractController
- AbstractController::ActionNotFound
- AbstractController::AssetPaths
- AbstractController::Base
- AbstractController::Callbacks
- AbstractController::Callbacks::ClassMethods
- AbstractController::Collector
- AbstractController::DoubleRenderError
- AbstractController::Error
- AbstractController::Helpers
- AbstractController::Helpers::ClassMethods
- AbstractController::Layouts
- AbstractController::Layouts::ClassMethods
- AbstractController::Layouts::ClassMethods::LayoutConditions
- AbstractController::Logger
- AbstractController::Railties
- AbstractController::Railties::RoutesHelpers
- AbstractController::Rendering
- AbstractController::Rendering::ClassMethods
- AbstractController::Translation
- AbstractController::UrlFor
- AbstractController::UrlFor::ClassMethods
- AbstractController::ViewPaths
- AbstractController::ViewPaths::ClassMethods
- Sprockets
- Sprockets::Bootstrap
- Sprockets::Compressors
- Sprockets::Helpers
- Sprockets::Helpers::IsolatedHelper
- Sprockets::Helpers::RailsHelper
- Sprockets::Helpers::RailsHelper::AssetPaths
- Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError
- Sprockets::Railtie
- Sprockets::StaticCompiler
- HTML
- HTML::FullSanitizer
- HTML::LinkSanitizer
- HTML::Sanitizer
- HTML::Selector
- HTML::Tag
- HTML::WhiteListSanitizer
- Mime
- Mime::Mimes
- Mime::Type
- ActionPack
- Object
- Rack

No matching classes.

# ActionView::Helpers::FormBuilder

### Attributes

multipart[R]
multipart?[R]
object[RW]
object_name[RW]
options[RW]
parent_builder[R]

### Public Class Methods

_to_partial_path() click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1253
    def self._to_partial_path
      @_to_partial_path ||= name.demodulize.underscore.sub!(/_builder$/, '')
    end

new(object_name, object, template, options, proc) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1265
    def initialize(object_name, object, template, options, proc)
      @nested_child_index = {}
      @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
      @parent_builder = options[:parent_builder]
      @default_options = @options ? @options.slice(:index, :namespace) : {}
      if @object_name.to_s.match(/\[\]$/)
        if object ||= @template.instance_variable_get("@#{Regexp.last_match.pre_match}") and object.respond_to?(:to_param)
          @auto_index = object.to_param
        else
          raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}"
        end
      end
      @multipart = nil
    end

### Public Instance Methods

button(value=nil, options={}) click to toggle source

Add the submit button for the given form. When no value is given, it checks if the object is a new resource or not to create the proper label:

    <%= form_for @post do |f| %>
      <%= f.button %>
    <% end %>

In the example above, if @post is a new record, it will use "Create Post" as submit button label, otherwise, it uses "Update Post".

Those labels can be customized using I18n, under the helpers.submit key and accept the %{model} as translation interpolation:

    en:
      helpers:
        button:
          create: "Create a %{model}"
          update: "Confirm changes to %{model}"

It also searches for a key specific for the given object:

    en:
      helpers:
        button:
          post:
            create: "Add %{model}"

    # File lib/action_view/helpers/form_helper.rb, line 1401
    def button(value=nil, options={})
      value, options = nil, value if value.is_a?(Hash)
      value ||= submit_default_value
      @template.button_tag(value, options)
    end

check_box(method, options = {}, checked_value = "1", unchecked_value = "0") click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1323
    def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
      @template.check_box(@object_name, method, objectify_options(options), checked_value, unchecked_value)
    end

collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) click to toggle source

    # File lib/action_view/helpers/form_options_helper.rb, line 645
    def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
      @template.collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options))
    end

date_select(method, options = {}, html_options = {}) click to toggle source

    # File lib/action_view/helpers/date_helper.rb, line 1049
    def date_select(method, options = {}, html_options = {})
      @template.date_select(@object_name, method, objectify_options(options), html_options)
    end

datetime_select(method, options = {}, html_options = {}) click to toggle source

    # File lib/action_view/helpers/date_helper.rb, line 1057
    def datetime_select(method, options = {}, html_options = {})
      @template.datetime_select(@object_name, method, objectify_options(options), html_options)
    end

emitted_hidden_id?() click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1407
    def emitted_hidden_id?
      @emitted_hidden_id ||= nil
    end

fields_for(record_name, record_object = nil, fields_options = {}, &block) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1292
    def fields_for(record_name, record_object = nil, fields_options = {}, &block)
      fields_options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
      fields_options[:builder] ||= options[:builder]
      fields_options[:parent_builder] = self
      fields_options[:namespace] = fields_options[:parent_builder].options[:namespace]

      case record_name
      when String, Symbol
        if nested_attributes_association?(record_name)
          return fields_for_with_nested_attributes(record_name, record_object, fields_options, block)
        end
      else
        record_object = record_name.is_a?(Array) ? record_name.last : record_name
        record_name   = ActiveModel::Naming.param_key(record_object)
      end

      index = if options.has_key?(:index)
        "[#{options[:index]}]"
      elsif defined?(@auto_index)
        self.object_name = @object_name.to_s.sub(/\[\]$/,"")
        "[#{@auto_index}]"
      end
      record_name = "#{object_name}#{index}[#{record_name}]"

      @template.fields_for(record_name, record_object, fields_options, &block)
    end

file_field(method, options = {}) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1336
    def file_field(method, options = {})
      self.multipart = true
      @template.file_field(@object_name, method, objectify_options(options))
    end

grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) click to toggle source

    # File lib/action_view/helpers/form_options_helper.rb, line 649
    def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
      @template.grouped_collection_select(@object_name, method, collection, group_method, group_label_method, option_key_method, option_value_method, objectify_options(options), @default_options.merge(html_options))
    end

hidden_field(method, options = {}) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1331
    def hidden_field(method, options = {})
      @emitted_hidden_id = true if method == :id
      @template.hidden_field(@object_name, method, objectify_options(options))
    end

label(method, text = nil, options = {}, &block) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1319
    def label(method, text = nil, options = {}, &block)
      @template.label(@object_name, method, text, objectify_options(options), &block)
    end

multipart=(multipart) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1248
    def multipart=(multipart)
      @multipart = multipart
      parent_builder.multipart = multipart if parent_builder
    end

radio_button(method, tag_value, options = {}) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1327
    def radio_button(method, tag_value, options = {})
      @template.radio_button(@object_name, method, tag_value, objectify_options(options))
    end

select(method, choices, options = {}, html_options = {}) click to toggle source

    # File lib/action_view/helpers/form_options_helper.rb, line 641
    def select(method, choices, options = {}, html_options = {})
      @template.select(@object_name, method, choices, objectify_options(options), @default_options.merge(html_options))
    end

submit(value=nil, options={}) click to toggle source

Add the submit button for the given form. When no value is given, it checks if the object is a new resource or not to create the proper label:

    <%= form_for @post do |f| %>
      <%= f.submit %>
    <% end %>

In the example above, if @post is a new record, it will use "Create Post" as submit button label, otherwise, it uses "Update Post".

Those labels can be customized using I18n, under the helpers.submit key and accept the %{model} as translation interpolation:

    en:
      helpers:
        submit:
          create: "Create a %{model}"
          update: "Confirm changes to %{model}"

It also searches for a key specific for the given object:

    en:
      helpers:
        submit:
          post:
            create: "Add %{model}"

    # File lib/action_view/helpers/form_helper.rb, line 1368
    def submit(value=nil, options={})
      value, options = nil, value if value.is_a?(Hash)
      value ||= submit_default_value
      @template.submit_tag(value, options)
    end

time_select(method, options = {}, html_options = {}) click to toggle source

    # File lib/action_view/helpers/date_helper.rb, line 1053
    def time_select(method, options = {}, html_options = {})
      @template.time_select(@object_name, method, objectify_options(options), html_options)
    end

time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) click to toggle source

    # File lib/action_view/helpers/form_options_helper.rb, line 653
    def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
      @template.time_zone_select(@object_name, method, priority_zones, objectify_options(options), @default_options.merge(html_options))
    end

to_model() click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1261
    def to_model
      self
    end

to_partial_path() click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1257
    def to_partial_path
      self.class._to_partial_path
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.