Search code examples
ruby-on-railsruby-on-rails-3activeadminformtastic

active admin / formtastic , add all inputs in a single block


A report, has_many answers, and an answer belongs_to report. The nested form is displayed and works, but for the 5 answers I have

Add Answer

Answer __

Add Answer

Answer __

[next 3]

How can i group them in one single block with title "Add Answer", and 5 inputs ?

  form do |f|
    f.inputs "New Report" do 
      f.input :title
      f.input :type
      f.input :help_text
      f.input :text_box_present
      f.input :text_box_default
      f.input :template_id
    end

    f.inputs "ADD Answers", for: :answers do |a|
      a.input :text, label: "Answer", required: false
    end
    f.actions  
  end 

Solution

  • Wow, this is some elegant stuff that active admin and formtastic provides for nested attributes

    f.inputs "Answers"  do
      f.has_many :answers do |a|
        a.input :text, label: "Answer", required: false
      end 
    end
    

    It will auto add a delete/add button with javascript, for adding multiple answers