0

Member (테이블 용)를 만드는 동안 문제가 있습니다. '신입 회원'을 클릭 할 때마다 '신입 회원'을 만들 때마다 '제출'을 클릭 한 것처럼 자동으로 새 회원이 저장됩니다. 양식을 조정하면서 페이지를 다시로드 할 때마다 멤버도 만들어집니다. 내 컨트롤러에서 오타가있을 수 있습니다. 여기 'def new'가 있습니다.Twitter Bootstrap Rails : "NEW"를 클릭하면 저장됩니다.

def new 
    @member = Member.new 
    @member.association_id = @association.id 
    @member.save 
    3.times { @member.submembers << Submember.new() } 
end 

그렇지 않으면 일부 스크립트에서 오류가 발생할 수 있습니다. 질문은 어떻게 해결할 수 있습니까?

감사합니다.

다른 정보가 필요하면 여기에 의견을 남기십시오.

오류 메시지 :

Problem: 
Calling Document.find with nil is invalid. 
Summary: 
Document.find expects the parameters to be 1 or more ids, and will return a single document if 1  id is provided, otherwise an array of documents if multiple ids are provided. 
Resolution: 
Most likely this is caused by passing parameters directly through to the find, and the parameter either is not present or the key from which it is accessed is incorrect. 
+0

, 유일한 문제 : 당신이 association_id와 모델을 저장하는 행동을 만들 제출해야

def new @member = Member.new 3.times { @member.submembers << Submember.new() } end 

및 양식 : 당신의 코드는 같아야합니다 새 회원을 제출하기 위해 양식에 액세스 할 때 자동으로 회원을 만드는 것입니다. 자동으로 생성되는 '멤버'를 데이터베이스에 저장하는 것을 멈추게하면됩니다. –

답변

0

당신은 새로운 액션의 멤버를 저장하지 말아야 함을 의미한다. 나는 테이블에 포함 할 멤버를 만드는거야

def create 
    @member = Member.new(params[:member]) 
    @member.association_id = @association.id 
    if @member.save 
    redirect_to members_path, :notice => "Member was successfully created" 
    else 
    render :new 
    end 
end 
+0

나는 이것을 지금 시도했지만, MongoID 오류 만 있으면 check_access_parent 행과 관련이있다. 여기에 질문에 오류 메시지를 적어 두겠습니다. –

+0

회원 수 has_many 문서가 있습니까? 양식에 문제가있을 수 있습니다 (양식의 매개 변수가 유효하지 않습니다). Member와 Document는 MongoID 모델입니까? 이 오류의 원인은 무엇입니까? create @ member.save? –

관련 문제