class ActiveAdmin::Views::ActiveAdminForm

Public Instance Methods

actions(*args, &block) click to toggle source
# File lib/active_admin/views/components/active_admin_form.rb, line 75
def actions(*args, &block)
  block_given? ?
    insert_tag(SemanticActionsProxy, form_builder, *args, &block) :
    actions(*args) { commit_action_with_cancel_link }
end
add_create_another_checkbox() click to toggle source
# File lib/active_admin/views/components/active_admin_form.rb, line 87
def add_create_another_checkbox
  if %w(new create).include?(helpers.action_name) && active_admin_config && active_admin_config.create_another
    current_arbre_element.add_child(create_another_checkbox)
  end
end
build(resource, options = {}, &block) click to toggle source
# File lib/active_admin/views/components/active_admin_form.rb, line 27
def build(resource, options = {}, &block)
  @resource = resource
  options = options.deep_dup
  options[:builder] ||= ActiveAdmin::FormBuilder
  form_string = helpers.semantic_form_for(resource, options) do |f|
    @form_builder = f
  end

  @opening_tag, @closing_tag = split_string_on(form_string, "</form>")
  instance_eval(&block) if block_given?

  # Rails sets multipart automatically if a file field is present,
  # but the form tag has already been rendered before the block eval.
  if multipart? && @opening_tag !~ /multipart/
    @opening_tag.sub!(/<form/, '<form enctype="multipart/form-data"')
  end
end
has_many(*args, &block) click to toggle source
# File lib/active_admin/views/components/active_admin_form.rb, line 93
def has_many(*args, &block)
  insert_tag(HasManyProxy, form_builder, *args, &block)
end
input(*args) click to toggle source
# File lib/active_admin/views/components/active_admin_form.rb, line 71
def input(*args)
  proxy_call_to_form :input, *args
end
inputs(*args, &block) click to toggle source
# File lib/active_admin/views/components/active_admin_form.rb, line 45
def inputs(*args, &block)
  if block_given?
    form_builder.template.assigns[:has_many_block] = true
  end
  if block_given? && block.arity == 0
    wrapped_block = proc do
      wrap_it = form_builder.already_in_an_inputs_block ? true : false
      form_builder.already_in_an_inputs_block = true
      content = form_builder.template.capture do
        block.call
      end
      form_builder.already_in_an_inputs_block = wrap_it
      content
    end
    insert_tag(SemanticInputsProxy, form_builder, *args, &wrapped_block)
  else
    # Set except option to prevent sensitive fields from being shown in forms by default.
    opts = args.extract_options!
    opts[:except] ||= []
    ActiveAdmin.application.filter_attributes.each { |e| opts[:except] << e }
    args << opts

    proxy_call_to_form(:inputs, *args, &block)
  end
end
multipart?() click to toggle source
# File lib/active_admin/views/components/active_admin_form.rb, line 97
def multipart?
  form_builder && form_builder.multipart?
end
object() click to toggle source
# File lib/active_admin/views/components/active_admin_form.rb, line 101
def object
  form_builder.object
end

Private Instance Methods

create_another_checkbox() click to toggle source
# File lib/active_admin/views/components/active_admin_form.rb, line 107
def create_another_checkbox
  create_another = params[:create_another]
  label = @resource.class.model_name.human
  Arbre::Context.new do
    li class: "create_another" do
      input(
        checked: create_another,
        id: "create_another",
        name: "create_another",
        type: "checkbox"
      )
      label(I18n.t("active_admin.create_another", model: label), for: "create_another")
    end
  end
end