Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin won't save has many and belongs to many field

I have 2 models. Category and Post. They are connected using a has_many_and_belongs_to_many relationship. I checked in the rails console and the relationship works.

I created checkboxes in activeadmin to set the post categories using this form field:

f.input :categories, as: :check_boxes, collection: Category.all

The problem is when I try to save it because every other field data (title, body, meta infos etc.) is saved, but the category stays the same even if I unchecked it, or checked another too.

I am using strong parameters like this:

post_params = params.require(:post).permit(:title,:body,:meta_keywords,:meta_description,:excerpt,:image,:categories)

Please give me some suggestions to make active admin save the categories too!

Best Wishes, Matt

like image 252
Allanon Avatar asked Jun 19 '13 20:06

Allanon


1 Answers

Try this in AA:

    controller do
      def permitted_params
        params.permit post: [:title, :body, :meta_keywords, :meta_description, :excerpt, :image, category_ids: []]
      end
    end
like image 168
mindhalt Avatar answered Sep 19 '22 18:09

mindhalt