Method: SimpleForm::FormBuilder#input_field

Defined in:
lib/simple_form/form_builder.rb

- (Object) input_field(attribute_name, options = {})

Creates a input tag for the given attribute. All the given options are sent as :input_html.

Examples

simple_form_for @user do |f|
  f.input_field :name
end

This is the output html (only the input portion, not the form):

<input class="string required" id="user_name" maxlength="100"
   name="user[name]" type="text" value="Carlos" />


133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/simple_form/form_builder.rb', line 133

def input_field(attribute_name, options = {})
  options = options.dup
  options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *ATTRIBUTE_COMPONENTS)
  options = @defaults.deep_dup.deep_merge(options) if @defaults

  input      = find_input(attribute_name, options)
  wrapper    = find_wrapper(input.input_type, options)
  components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS) + [:input]
  components = components.map { |component| SimpleForm::Wrappers::Leaf.new(component) }

  SimpleForm::Wrappers::Root.new(components, wrapper.options.merge(wrapper: false)).render input
end

Comments