2012-06-06 1 views
5

activeadmin을 사용하고 있으며 그것을 사용하는 많은 사람들이 formtastic을 내장하고 있습니다. ProjectResources와의 많은 연관성을 가진 Project라는 모델이 있습니다.Formtastic/ActiveAdmin 다중 선택 다수 체크 박스 연결 문제

Project 용 활성 관리자의 내 "편집"및 "생성"양식이 그렇게 보입니다.

form do |f| 
      f.inputs "Project" do 
      f.input :name, :input_html => { :readonly => true } 
      end 
      f.inputs "Resources" do 
      f.input :id, :label => "Selected Resources", 
       :as => :check_boxes, 
       :multiple => true, 
       :collection => ProjectResource.all, 
       :selected => @resources 
      end 
      f.buttons 
    end 

내 체크 박스가 잘 렌더링되며이 시점에서 오류가 발생하지 않습니다. 당신이 짐작할 수있는 문제는 "편집"페이지를 렌더링 할 때 프로젝트에 이미 ProjectResource가 연관되어있는 경우 체크 박스 영역의 항목을 "선택됨"으로 표시하고 싶습니다.

지금 체크 박스는 모두 선택 해제 상태입니다. activeadmin의 최신 버전을 사용하고 있으며 formtastic에는 다음 버전이 설치되어 있습니다. (2.2.0, 2.1.1, 2.1.0, 2.0.2, 1.2.4)

이 시점에서 activeadmin의 버전을 확인하지 못했습니다. 내 추측은 최신 버전입니다.

나를 위해

답변

9

, 간단한 :

ActiveAdmin.register Subscription do 

    form do |f| 
    f.inputs do 
     f.input :users, as: :check_boxes 
     # other fields... 
    end 
    f.buttons 
    end 
end 

은 작동합니다.

더 코드 :

- 사용자 클래스

class User < ActiveRecord::Base 
    has_and_belongs_to_many :users 
    attr_accessible :fields... 
end 

-Subscription 클래스

class Subscription < ActiveRecord::Base 
    has_and_belongs_to_many :subscriptions 
    attr_accessible :fields... 
end 

PS 내가 ActiveAdmin을 0.4.2 및 Formtastic 2.0.2을 사용하고 있습니다.