문제

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

도움이 되었습니까?

해결책 2

try add

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

다른 팁

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

ActiveAdmin.register Product do
  permit_params category_ids: []
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top