Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:14:32+00:00 2026-06-12T00:14:32+00:00

I have 2 activeadmin resources, both are subclasses of a model, using STI. For

  • 0

I have 2 activeadmin resources, both are subclasses of a model, using STI. For example:

base_model.rb

class BaseModel < ActiveRecord::Base

end

male_model.rb

class MaleModel < BaseModel

end

female_model.rb

class FemaleModel < BaseModel

end

admin/male_model.rb

ActiveAdmin.register MaleModel do
  menu :parent => "Models", :label => "Male Model"

  # A big long custom form follows...
  form do |f|
    f.inputs
    f.buttons
  end
end

admin/female_model.rb

ActiveAdmin.register FemaleModel do
  menu :parent => "Models", :label => "Female Model"

  # The SAME big long custom form follows...
  form do |f|
    f.inputs
    f.buttons
  end
end

What would be the correct way to render the same form, but create a record of a different subclass, either MaleModel or FemaleModel?

What I’m doing now is maintaining 2 activeadmin resources with almost exactly the same (bulky) code within. Totally unDRY. Please share what you’ve done in this situation.

John

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:14:33+00:00Added an answer on June 12, 2026 at 12:14 am

    I haven’t try this but you could define an @object variable in the controller:

    controller do
        before_filter :set_object, :only => [:new, :edit]
        ....
        def set_object
            @object = MaleModel.find(params[:id]) rescue MaleModel.new
        end
    end
    

    And then you could render a form and use the variable @object instead of @male_model or @female_model.

    form :partial => "models/form"
    
    # app/views/models/_form.html.erb
    <%= semantic_form_for [:admin, @object] do |f| %>
        <%= f.inputs %>
        <%= f.actions %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these associations: class Course < ActiveRecord::Base has_many :signup has_many :user, :through =>
I'm using Rails 3, ActiveAdmin and Kaminari. I have this on the documents.rb file
I have an ActiveAdmin app with a simple model that I want to persist
I have a rails app that is using Devise, with a User model, no
In my ActiveAdmin model I have a custom scope to show deleted records and
I have the following form parsial that I'm using in activeadmin on in a
I'm using ActiveAdmin and Formtastic. I have an invoice form that has a drop
I have the following setup: A model called Categories. These categories are managed using
I have a resource Photos, which belongs to Adverts. In ActiveAdmin, users should be
I have a ActionAdmin model, which is used as ActionAdminInline in the InvoiceAdmin model.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.