ActiveAdmin sets up form for belongs_to

I have the following associations:

class Course < ActiveRecord::Base
  has_many :signup
  has_many :user, :through => :signup

  accepts_nested_attributes_for :signup
end

class User < ActiveRecord::Base
  has_many :signup
  has_many :course, :through => :signup

  accepts_nested_attributes_for :signup
end

class Signup < ActiveRecord::Base
  belongs_to :course
  belongs_to :user
end

Now I would like to configure the ActiveAdmin form for "Registration", so it displays the name of the courses and the username as the selected one, and not as a text field.

The default form already does this, however I need to customize the form further, and I cannot reproduce the default form.

+5
source share
1 answer

Your form block will look something like this in yours admin/signups.rb:

form do |f|
    f.input :course
    t.input :user
end

, course user , collection_select - a name , id . input, .

form do |f|
    f.input :course, :as => :string
end

course_id, , , . " ", input . f.inputs, .

form do |f|
    f.inputs "Basic Details" do
        f.input :course
        f.input :user
    end
end
+6

All Articles