0
votes

When using activeadmin with rails 4, permit_params has to be set to allow fields to be saved.

simple fields are working, however a multi select for a has_many field is silently ignored. How can i set permit_params for that field?

so home has_many providers, and my admin looks like this:

ActiveAdmin.register Home do
  permit_params :title, :intro, :providers, :providers_attributes => [:id]
  menu :parent => "Content" , :label => "Home Page"
   form do |f|
    f.semantic_errors *f.object.errors.keys
    f.inputs do
      f.input :title
      f.input :intro
      f.input :providers
    end
    f.actions
  end

  index do
    column :link
    actions
  end
end
1

1 Answers

0
votes

I don't know if they changed it with Rails 4 .. but I've always done it this way

form do |f|
    f.semantic_errors *f.object.errors.keys
    f.inputs do
        f.input :title
        f.input :intro
    end
    f.has_many :providers do |pf|
        pf.input :title #or whatever attributes you have there
        pf.input :_destroy, :as => :boolean, :label => "Delete" if !pf.object.nil?
    end
    f.actions
end

And in your model.rb you should have something similar to

attr_accessible :providers_attributes

has_many :providers
accepts_nested_attributes_for :providers, :allow_destroy => true

Let me know if that helps !