module ActiveAdmin module Views class FormtasticProxy < ::Arbre::Rails::Forms::FormBuilderProxy def split_string_on(string, match) return "" unless string && match part_1 = string.split(Regexp.new("#{match}\\z")).first [part_1, match] end def opening_tag @opening_tag || "" end def closing_tag @closing_tag || "" end def to_s opening_tag << children.to_s << closing_tag end end class ActiveAdminForm < FormtasticProxy builder_method :active_admin_form_for 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, "") 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!(/