1

我需要一个简单的表格来添加一系列电话号码。

ActiveAdmin.register Did do
    # ..
    collection_action :add_range, :method => :get do
    end
    collection_action :add_range, :method => :post do
    end
end

<%= semantic_form_for [:admin, :dids, :add_range] do |f| %>
    <%= f.inputs :start, :end %>
    <%= f.buttons :commit %>
<% end %>

以上以“符号:类的未定义方法`model_name'”失败。

如何定义这样的不直接使用对象的表单?

4

3 回答 3

2

刚刚试过,这将工作:

<%= semantic_form_for :range, :url => add_range_admin_dids_path do |f| %>
    <%= f.inputs :start, :end %>
    <%= f.buttons :commit %>
<% end %>

然后在 params[:range] 中找到发布的参数

于 2012-07-15T20:34:08.943 回答
1

我有类似的情况,我需要自定义表单操作属性。因此,我发现实现此目的的最佳方法是在相应视图的文件夹中创建部分表单。

首先告诉您的资源您将使用自定义表单,因此将此行添加到您的资源文件中:

# app/admin/organizations.rb

form partial: "form"

现在您可以使用Arbre Components创建您的部分,如下例所示:

# app/views/admin/organizations/_form.html.arb

active_admin_form_for [:admin, resource] do |f|
  tabs do
    tab 'General Configuration' do
      f.inputs 'Organization Details' do
        admin_accounts = User.with_role(:admin).order('email ASC')
        site_collection = Site.where("subdomain <> ''").map { |site| ["#{site.subdomain}", site.id ]}
        f.input :name
        f.input :kind, :as => :enum
        f.input :carereceiver_kind, :as => :enum
        f.input :account_manager, :as => :select ,:collection => admin_accounts
        f.input :site_id, as: :select ,collection: site_collection
        f.input :office_phone
        f.input :office_fax
        f.input :office_address
        f.input :company_logo, :as => :file
        f.input :letterhead
        f.input :base_url, label: 'BASE URL'
        f.input :dynamics_url, label: 'DYNAMICS URL'
        f.input :genoa_site_id, label: 'GENOA SITE ID'
      end

      f.inputs 'Organization Settings' do
        f.input :demo_account
        f.input :appointment_not_started_notifications_enabled
        f.input :erx_enabled
        f.input :patients_can_book_appointments
        f.input :new_providers_can_manage_their_own_availability_by_default
        f.input :clarity_enabled
        f.input :whitelist_enabled
        f.input :bed_form_enabled
        f.input :patient_email_required, label: 'Require patient email addresses'
        f.input :patient_credit_card_required, label: 'Require patient credit card information'
        f.input :enable_patient_survey, label: 'Enable patient survey'
        f.input :enable_provider_survey, label: 'Enable provider survey'
        f.input :rcopia4_enabled, label: 'Rcopia 4 enabled'
        f.input :share_notes_across_providers_enabled
        f.input :d2c_mode
        f.input :sso_login_only
        f.input :allow_invited_patients_to_complete_profile
        f.input :allow_overlapping_appointments, as: :select
        f.input :media_mode, :as => :enum
      end

      f.inputs('Organization Contacts', { class: 'organization_contacts_section' }) do
        saved_contacts = f.object.organization_contacts.count
        n = 5 - saved_contacts.to_i
        n.times do
          f.object.organization_contacts.build
        end
        contact_counter = 0
        f.fields_for :organization_contacts do |m|
          contact_counter = contact_counter +  1
          m.inputs "Contact #{contact_counter}" do
            m.input :name, placeholder: 'Name'
            m.input :title, placeholder: 'Title'
            m.input :email, placeholder: 'Email'
            m.input :phone_number, placeholder: 'Phone Number'
          end
        end
      end
    end

    tab 'Appointment Parser Configuration' do
      f.inputs 'Appointment Parser Configuration' do
        f.input :appointment_parsers, as: :select, input_html: { multiple: true }
      end
    end

    tab 'EMR Settings' do
      f.inputs 'Settings' do
        f.input :emr_integrated, label: 'Enable EMR integration'
        f.input :emr_processor_type, as: :select, collection: Organization::AVAILABLE_EMR_PROCESSORS
        f.input :send_to_emr, label: 'Enable integration from 1DW to EMR'
        f.input :receive_from_emr, label: 'Enable integration from EMR to 1DW'
      end
    end

    tab 'Athena EMR Settings' do
      f.inputs 'Settings' do
        f.input :athena_practice_id, label: 'Athena Practice ID', input_html: { disabled: !f.object.has_athena_processor? }
        f.input :athena_department_number, label: 'Athena Department ID', input_html: { disabled: !f.object.has_athena_processor? }
      end
    end
  end

  f.actions
end

正如您所看到的,admin_organization_path您可以将 URL 指向您想要的任何其他 URL,但您也可以自定义method发送表单。

还要确保你使用resourceactive_admin_form_for块,因为如果你尝试使用类似@organization.

每当您配置了相应的模型关系时,该表单包含一种将嵌套资源添加到主体资源的可能方式。

有了这个,它应该可以正常工作。我希望它对其他人有用。

于 2018-05-14T23:14:29.467 回答
0

我很确定您需要在调用semantic_form_for. 由于您的操作是一个集合操作,它不会作用于特定的 DID,那么您要创建什么模型?范围模型?如果是这种情况,你应该有类似的东西:

<%= semantic_form_for [:admin, @range] do |f| %>
  <% ... %>
  <%= f.buttons :commit
<% end %>

当然@range应该像Range.new在控制器中那样初始化。

编辑:意识到你不想使用一个对象有点晚。在文档中它表明您可以使用semantic_form_for :login,但它可能不适用于嵌套/命名空间的表单。您可能必须指定urlwith:url => admin_add_range_dids_path或类似的东西。只需检查rake routes以找到正确的命名。不确定模型是由 ActiveAdmin 还是 Formtastic 调用,所以这仍然可能不起作用,但值得一试。

于 2012-04-11T11:45:46.127 回答