Configure the label of Active Admin has_many

MatisMasters picture MatisMasters · Nov 29, 2011 · Viewed 9.3k times · Source

Well I have a two models related with a on-to-many assoc.

#models/outline.rb
    class Outline < ActiveRecord::Base
      has_many :documents
    end

#models/document.rb
    class Document < ActiveRecord::Base
      belongs_to :outline
    end

#admin/outlines.rb
    ActiveAdmin.register Outline do
      form do |f|
        f.inputs "Details" do
          f.input :name, :required => true
          f.input :pages, :required => true
          ...
          f.buttons
        end
        f.inputs "Document Versions" do 
          f.has_many :documents, :name => "Document Versions"  do |d|
            d.input :file, :as => :file
            d.buttons do
              d.commit_button :title => "Add new Document Version"
            end
          end
        end
      end
    end

Well as you can see in the admin/outlines.rb I already tried setting up the :name, in the has_many :documents, and the :title in the commit_button, but neither of that options work, I also tried with :legend, :title, and :label, instead of :name in the .has_many. Not working.

This is the result of that code: Screenshot

What I want to display is "Document Versions" instead of "Documents", and "Add new Document Version" instead of "Add new Document"

If someone can have a solution it would be great

Answer

timfjord picture timfjord · Sep 6, 2013

To set has_many header you can use

f.has_many :images, heading: 'My images' do |i|
  i.input :src, label: false
end

See here