Search code examples
ruby-on-railsrubyruby-on-rails-3activeadminnested-form-for

Add new button in has_many in activeadmin rails


f.has_many :offers,heading: 'Offers' do |item|
  item.input :quantity
  item.input :offer_type_id, :prompt => 'Select Offer Type', :as => :select, :collection => OfferType.all.map{|m| [m.title, m.id]}
    item.input :_destroy, :as => :boolean
end

It works fine and has_many association created. I want that the button for adding associated data automatically clicked or open when I load page.

Add new Offer

Instead that user click on it for first associated data it automatically clicked


Solution

  • In AA controller block you need yo build offer - it will add the offer's fields to the form:

    controller do
      def new
        super do
          resource.offers.build
        end
      end
    end