"add"를 클릭하면 새 레코드를 만들지 않는 레일에 간단한 form_for가 있습니다. Contact라는 중첩 된 리소스가있는 Opportunity라는 모델이 있습니다. 연락처 양식은 문제가있는 양식입니다. 내 양식을 작동하는 비슷한 중첩 된 리소스와 비교했지만 문제를 찾을 수 없었습니다.form_for not working rails 4.0
연락처 컨트롤러 :
보기/연락처/new.html.erb :
<div id="new_contact_form">
<%= form_for ([@opportunity, @opportunity.contacts.new]) do |f| %>
<div class="field">
<%= f.label "Contact Info:" %> <br />
<%= f.text_area :first_name %>
</div>
<div class="actions">
<%= f.submit 'Add' %>
</div>
<% end %>
</div>
여기
def new
@contact = Contact.new
end
def create
@opportunity = Opportunity.find(params[:opportunity_id])
@contact = @opportunity.contacts.new(contact_params)
if @contact.save
redirect_to @opportunity, notice: 'Contact has been added'
else
redirect_to @opportunity, alert: 'Unable to add Contact'
end
end
def contact_params
params.require(:contact).permit(:first_name)
end
내가 문제를 데 특정 형태 여기 내 코드입니다
제발 도와주세요 ... 감사합니다 !!!
def new
@opportunity = Opportunity.find(params[:opportunity_id])
@contact = @opportunity.contacts.build
end
및 양식은 다음과 같습니다 :
을 당신은'new' 행동에 인스턴스 변수 opportunity''@를 정의 할 필요가 렌더링 무엇 인 'new.html.erb'. – vee