1

과를 통해 많은있다 : 나는 ActiveAdmin을을 사용하고 관계를 설명하기 위해 체크 박스를 설정해야하고레일 (4) 나는 다음과 같은 표준 관계를 설정하려고 활성 관리자

class Category < ActiveRecord::Base 
    has_many :post_categories 
    has_many :posts, :through => :post_categories 
    accepts_nested_attributes_for :post_categories 
end 

class Post < ActiveRecord::Base 
    has_many :post_categories 
    has_many :categories, :through => :post_categories 
    accepts_nested_attributes_for :post_categories 
    attr_accessor :category_ids 
end 

class PostCategory < ActiveRecord::Base 
    belongs_to post 
    belongs_to category 
end 

. 확인란을 저장하는 데 여러 가지 방법을 시도했습니다. 여기 내 관리 post.rb 파일입니다 : 나는 레일 튜토리얼과 같이 데이터베이스를 설정

permit_params :content, :categories 
permit_params :content, post_categories_attributes: [:id, :post_id, :category_id] 
permit_params :content, category_ids: [:id] 

같은

같은 다른 허가 PARAMS을 시도

ActiveAdmin.register Post do 

    permit_params :content, category_ids: [] 

    form do |f| 
    f.inputs # Include the default inputs 
    f.inputs "Categories" do 
     f.input :categories, as: :check_boxes, collection: Category.all 
    end 
    f.actions # Include the default actions 
    end 
end 

과의 관계는 다른 곳에서 작동하는 것 같다 activeadmin에서 저장하는 것을 제외하고는 나는 모든 매개 변수를 허용하기 위해 param.permit!을 사용하려했지만, 여전히 운이 없다.

겉으로보기에는 똑같은 질문을 많이했지만 많은 사람들이 다른 대답을하고 아무 것도 작동하지 않는 것 같습니다.

무엇이 잘못 되었나요?

+0

에 도움이 될 수 있습니다 가정 http://stackoverflow.com/a/24486212/3199803이 솔루션은 효과가 있었지만보다 간결한 방법이 있어야하는 것처럼 보였습니다. 같은 질문에 대한 다른 해결책이 나에게 적합하지 않습니다. – BreadnButter

+0

만들기 작업이 시작될 시점의 로그 파일에는 무엇이 있습니까? – nistvan

답변

0

조금 늦게하지만이 질문은 나를 위해 처음으로 인터넷 검색, 그래서 내가 다른 "Google 직원이"

#models/post.rb 

accepts_nested_attributes_for :categories#, allow_destroy: true 

#AA Post conf file 

permit_params :content, category_ids: [] 
관련 문제