2012-12-18 3 views
0

componenthas_many :framework 모델입니다. 양식의 구성 요소에 대한 프레임 워크를 연결하려면 나는했습니다 쓰기 :레일 양식 오류

<div class="field"> 
    <%= f.label :frameworks %><br /> 
    <%= f.collection_select :frameworks, Framework.all, :id, :name, {}, {:multiple => true} %> 
</div> 

하지만 지금은 나에게주고 :

Framework(#70243540172600) expected, got String(#70243531874180) 

그리고 하나 더 질문 :

숨기는 방법을

/쇼 단추가있는이 div? 목록이 거대 할 수 있기 때문입니다.

답변

0

구성 요소 has_many : frameworks 인 경우 collection_select를 사용할 수 없습니다. 이 경우 형태

: [: 성분]

<%= f.collection_select :frameworks, Framework.all, :id, :name ... etc... {:multiple => true} %> 

가 PARAMS를 반환 [: 워크] = "3", "4", "55"]. 그러나 component.frameworks는 Framework 객체 만 받아들이는 연관체이지만 Strings를 전달합니다.

<%= f.collection_select :framework_ids, Framework.all, :id, :name ... etc... %> 

무엇에 대한 버튼 :처럼 보이도록

class Component < ActiveRecord::Base 
    attr_accessible :framework_ids 

    def framework_ids=(ids) 
    ids.each do |framework_id| 
     frameworks << Framework.find(framework_id) 
    end 
    end 
end 

그런 다음 양식을 선택했다 :

당신은 캐릭터 라인 정수 (프레임 워크의 ID)의 배열을 받아 손으로 만든 접근을 사용해야합니다 ... 너 JQuery UI 물건을 배워야 해.