0

약 12 ​​시간 동안이 작업을 시도한 후에 구원을 위해 SO로 전환해야합니다. 여기 시나리오가 있습니다.레일 다른 컨트롤러의 중첩 된 폼 객체

저는 zurb foundation 4를 사용 중이며 내 대시 보드에서 중첩 된 리소스에 대한 모달 아약스 양식을 공개하려고합니다.

나는 다음과 같은 중첩 된 자원이 있습니다/1/노트/새로운 작품 좋은 교훈에서

resources :lessons, only: [:index, :edit, :show] do 
    resources :notes, only: [:new, :create, :edit, :delete] 
    end 

양식을. 그래서 같은

내 static_pages에 테이블이/집 :

<!--Reveal Form--> 
<div id="note-for" class="reveal-modal"> 
<% @lessons.each do |lesson| %> <--form now associated with proper object--> 
    <%= form_for Note.new, :url => new_lesson_note_path(lesson) do |f| %> 
     <div class="field"> 
     <%= f.label :content %> 
     <%= f.text_area :content %> 
     </div> 
     <div class="actions"> 
     <%= f.submit "Save", class: "small button"%> 
     </div> 
    <% end %> 
    <a class="close-reveal-modal">&#215;</a> 
    <% end %> 
</div> 

: 내 모든 마크 업에서

<table> 
    <thead> 
    <tr> 
     <th>Student</th> 
     <th>Subject</th> 
    </tr> 
    </thead> 
<% @lessons.each do |lesson| %> 
    <tr> 
     <td><%= link_to lesson.student.name, lesson %></td> 
     <td><%= lesson.subject.name %></td> 
     <td><%= link_to 'make a note', new_lesson_note_path(lesson), "data-reveal-id"=>"note-for" %></td> 
    </tr> 
<% end %> 

, 나는 기초에서 다음과 같은 형태의 모달을 공개했다 모달 렌더링이 잘되지만 양식을 제출하면 다음 오류가 throw됩니다.

No route matches [POST] "/lessons/1/notes/new" 

나는 진지하게 여기를 잃고 있습니다. 제발 도와주세요.

답변

1

!

13 시간의 땜질 후, 용액!

는 notes_controller.rb 조치가 제대로

def create 
    @lesson = Lesson.find(params[:lesson_id]) 
    @note = @lesson.notes.build(params[:note]) 
    if @note.save 
    respond_to do |format| 
     format.html { redirect_to root_path, notice: 'Lesson noted!' } 
     format.js 
    end 
    else 
     redirect_to root_path 
    end 
    end 

를 포맷 보장 계시 모달 DIV

<div id="note-for" class="reveal-modal"> 
    <% @lessons.each do |lesson| %> 
    ....... 
    <% end %> 
</div> 

내에서 루프를 추가하고 지금은 술집 끝나요! 고마워요 ole

2

나는 당신이 @lessons 변수와 함께 실수했다고 가정합니다. 귀하는 모델 대신 ur helper에 대한 모델 관계를 전달합니다. 이 시도 해결을 위해

:

마침내
#controller 
@lesson = Lesson.find(params[:lesson_id]) 

#view 
... 
<%= form_for Note.new, :url => new_lesson_note_path(@lesson) do |f| %> 
... 
+0

나는 실제로 이것을 시도 했어. 그러나 좋은 소식은 <% @ lessons.each do | lesson | %>. 편집 된 코드를 참조하십시오. 이제 문제는 라우팅 오류가 발생한다는 것입니다. 저는 (@lessons)이 양식을 단지 하나의 수업 대신에 수업 컬렉션과 연관시키고 있다고 생각합니다. –

+0

그게 뭔가 이상합니다. 때로는 문제에 몇 시간을 쓸 것입니다. 포기해라. SO에 대한 도움을 요청하십시오. 그리고 곧 내 질문을 입력하면 해결책이 내 머리 속으로 튀어 나옵니다. –