Question

I using rails 4.0.3 and am trying to set up many to many checkboxes in Active-Admin. The checkbox selections are not being saved. This is what i have

class Product < ActiveRecord::Base
  has_many :categorizations
  has_many :categories, :through => :categorizations
  accepts_nested_attributes_for :categorizations
end

class Category < ActiveRecord::Base
  has_many :categorizations
  has_many :products, :through => :categorizations
  accepts_nested_attributes_for :categorizations
end

class Categorization < ActiveRecord::Base
  belongs_to :category
  belongs_to :product
end

ActiveAdmin.register Product do

  permit_params :title, :price, category_ids:[:id]

  form do |f|
    f.semantic_errors *f.object.errors.keys
    f.inputs "Product" do
      f.input :title
      f.input :price
      f.input :categories, :as => :check_boxes
    end
    f.actions
  end
end

I have also tried using has_and_belongs_to_many but still cant not get the selections to save.

Any guidance would be highly appreciated.

Cheers

Was it helpful?

Solution 2

try add

permit_params :title, :price, category_ids:[:id], categories_attributes: [:id, :your_fields, :_update,:_create]

OTHER TIPS

I found that adding the following to your active_admin file, product.rb, fixes it.

ActiveAdmin.register Product do
  permit_params category_ids: []
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top