Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4.0.3 Active-Admin has_many checkboxes not saving

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

like image 688
user346443 Avatar asked Mar 17 '14 15:03

user346443


1 Answers

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

ActiveAdmin.register Product do
  permit_params category_ids: []
end
like image 127
jburris Avatar answered Sep 21 '22 11:09

jburris