How do I modify the form url with the ActiveAdmin Ruby gem?

active admin form
semantic_form_for activeadmin
active admin render partial
active admin gem
active admin link_to
activeadmin datepicker
active admin table_for
active admin sidebar

I'm using the ActiveAdmin ruby gem, which uses formtastic.

I have a form like below:

ActiveAdmin.register User do
    permit_params :first_name, :last_name, :age

    form do |f|
        input :first_name
        input :last_name
        input :age
        actions
    end
end

I want to modify the form URL to a custom URL which includes the user's ID (eg 7). Something like:

ActiveAdmin.register User do
    permit_params :first_name, :last_name, :age

    form url: "/api/customer/7/attempt", method: :post  do |f|
        input :first_name
        input :last_name
        input :age
        actions
    end
end

The above works (that is, the form url is changed). However, I'm hardcoding the user ID 7 in the URL. I need to do a variable interpolation. But I'm not sure I have access to the user object outside the block.

I have access to the user object within the block like

f.object.id

But not outside the block.

How do I overcome this problem?

Thank you.


I don't know if that's possible, I tried approaches like

resource.id
user.id
params[:id]

and they didn't work.

To solve this problem you can create custom form

form partial: 'form'

and specify url there.

How do I modify the form url with the ActiveAdmin Ruby gem?, I'm using the ActiveAdmin ruby gem, which uses formtastic. I have a form like below: ActiveAdmin.register User do permit_params :first_name,  How to Add In Page Editing Using Gem best_in_place. Jump to bottom. Best in place is a jQuery based Ajax plug in that can help us to add in place editing to our application that takes profit of Restful server-side controllers to allow users to edit stuff with no need of forms. We can easly integrate inline editing in active_admin with best_in_place.


I'm working with Rails 5 and ActiveAdmin with Arctic_Admin them and I found myself in a very similar situation where I need to customize the form action attribute. So, the best way I found to achieve this was by creating a partial form in the corresponding view's folder.

First tell your resource you are going to use a custom form, so add this line to your resource file:

# app/admin/organizations.rb

form partial: "form"

Now you can create your partial by using Arbre Components, like this example:

# 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

As you can see with admin_organization_path you can point the URL to any other you want but also you can customize the method to send the form.

Also make sure you use resource for the active_admin_form_for block because you will get an error if you try to use something like @organization.

The form contains a possible way to add nested resources to the principal one, every time you had configured the corresponding model relationships.

And with this, it should be working fine.

I hope it could be useful for someone else. ūüėÉ

Customizing resource retrieval, Every Active Admin resource corresponds to a Rails model. Nested associations in the same form also require an array, but it needs to be For example, to change 'New Offer' to 'Make an Offer' add the following in config/‚Äčlocales/[en].yml: |admin| admin.build_menu do |menu| menu.add label: "The Application", url: "/"¬† unable to retrieve data from a form in rails. ruby-on-rails. You need to display your form so instead of using <% %> you need to use <%= %>, checkout this answer for differences between them. By default forms use POST verb and you have defined a route for GET request. Change your form to this: <%= form_tag({action: :test}, {method: :get})


resource.id should work in your case

Forms, Forms. Active Admin gives you complete control over the output of the form by creating a thin DSL on top of Formtastic: This is a regular Rails partial so any template engine may be used. You can Customize the Create Another checkbox. You can create forms with nested models using the has_many method, even if your model uses has_one: The :allow_destroy option adds a checkbox to the end of the nested form allowing removal of the child object upon submission.


Custom Controller Actions, Active Admin allows you to override and modify the underlying controller which is generated for you. There are helpers to add collection and member actions,  Change datetime format. If you want to change the format you need to make sure that front-end and back-end formats are identical. And remember JS and Ruby datetime format have different syntaxes.


Custom Pages, Customizing the CSV format · Customizing the Form Customize the Menu. See the Menu Customize the breadcrumbs Customize the Namespace. We use  Active Admin is a Ruby on Rails framework for creating elegant backends for website administration. Enable developers to quickly create good-looking administration interfaces. Build a DSL for developers and an interface for businesses. Ensure that developers can easily customize every nook and cranny.


General Configuration, To translate Active Admin to a new language or customize an existing When using devise for authentication, you can use the devise-i18n gem to get the devise holds on to its own settings that inherit from the application's configuration. do |menu| menu.add label: "ActiveAdmin.info", url: "http://www.‚Äčactiveadmin.info",¬† This gem allows to change the default layout of ActiveAdmin without monkey patching its code. You can just use standard application layout templates to organize where ActiveAdmin layout sections should be rendered. Usage Available exports. The following layout template will render the default ActiveAdmin layout: