2013-01-24 2 views
3

양식에서 레코드를 만들려고합니다. 나는 railscast 136을 기초 작업으로 사용했습니다. 제출을 시도 할 때 부분적인 분실에 대해 500 오류가 발생합니다. 내가 컨트롤러에 연결된 자바 스크립트 뷰를 만들었지 만 모델과 같은 이름의 뷰를 요청하고 있습니다.Gettin 500 내부 서버 아약스 요청시 레일에 오류가 발생했습니다.

오류 메시지

500 내부 서버 오류 12ms

ActionView :: 템플릿 :: 오류에 완료

렌더링 약속/create.js.erb (3.8ms) (부분 약속 없음/검색 결과 : "/ 사용자 :: 사용자 :검색 결과 :: 사용자 :: {사용자 이름 :: 작성자 :/gjores/Sites/Rails/verkstad_test/app/views ") : 1 : $ ('# appointments') 추가 '< % = j render (@appointment) %>'); 앱 /보기/약속/create.js.erb : 1 : _app_views_appointments_create_js_erb___2325925946390315228_70273089113920' app/controllers/appointments_controller.rb:16:in에서 작성 '

컨트롤러

def create 
    @appointment = Appointment.new(params[:appointment]) 
    if @appointment.save 
     respond_to do |format| 
     format.html { redirect_to new_appointment_path, :notice => "Successfully created appointment." } 
     format.js 
     end 
    else 
     render :action => 'new' 
    end 
    end 

약속/new.html.erb

<div id="appointments"> 
    <%= render 'shared/appointment_part' %> 
</div> 
<% title "New Appointment" %> 
<table> 
<% @students.each do |s| %> 
<%= form_for @appointment, :remote => true do |f|%> 
    <%= f.error_messages %> 
    <tr> 
    <td><%= s.name %></td> 
    <td><%= f.label :week %></td> 
    <td><%= f.number_field :week %></td> 
    <td><%= f.label :teacher_id %></td> 
    <td><%= f.collection_select(:teacher_id, Teacher.all, :id, :name) %></td> 
    <%= f.hidden_field :student_id, :value => s.id %> 

    <td><%= f.submit %></td> 
    </tr> 
<% end %> 
<% end -%> 
</table> 

<p><%= link_to "Back to List", appointments_path %></p> 

약속/create.js.erb

012 3,516,
$('#appointments').append('<%= j render(@appointment) %>'); 

경로

appointments GET /appointments(.:format)   appointments#index 
       POST /appointments(.:format)   appointments#create 
new_appointment GET /appointments/new(.:format)  appointments#new 
edit_appointment GET /appointments/:id/edit(.:format) appointments#edit 
    appointment GET /appointments/:id(.:format)  appointments#show 
       PUT /appointments/:id(.:format)  appointments#update 
       DELETE /appointments/:id(.:format)  appointments#destroy 
     teachers GET /teachers(.:format)    teachers#index 
       POST /teachers(.:format)    teachers#create 
    new_teacher GET /teachers/new(.:format)   teachers#new 
    edit_teacher GET /teachers/:id/edit(.:format)  teachers#edit 
     teacher GET /teachers/:id(.:format)   teachers#show 
       PUT /teachers/:id(.:format)   teachers#update 
       DELETE /teachers/:id(.:format)   teachers#destroy 
notice_students POST /students/notice(.:format)  students#notice 
     students GET /students(.:format)    students#index 
       POST /students(.:format)    students#create 
    new_student GET /students/new(.:format)   students#new 
    edit_student GET /students/:id/edit(.:format)  students#edit 
     student GET /students/:id(.:format)   students#show 
       PUT /students/:id(.:format)   students#update 
       DELETE /students/:id(.:format)   students#destroy 
+0

스택 트레이스는 무엇인가? – nemesisdesign

+0

내 게시물을 업데이트했습니다 ... – Petter

답변

5

귀하의 스택 추적/레일 부분이라고 약속/appointments.html 또는 약속을 렌더링하기 위해 노력하고있다처럼

Missing partial appointments/appointment 

그래서 보이는 보여줍니다

이 appointments.js라는 파일을합니까 appointments.js. erb 또는 appointments.html.erb가 존재합니까?

그렇지 않다면 만듭니다.

그러나 나는 당신이 일을하려고하는 것은 당신이 당신의 페이지

$('#appointments').append('<%= j render(@appointment) %>'); 

난 당신이 라인을 필요가 있다고 생각에 몇 가지 요소의 HTML을 업데이트하려면 아래의 코드를 원한다고 생각으로 약속을 보여줄 것으로 의심 빨간색

$('#appointments').append('<%= j render :partial => 'appointments/appointment', :formats => :html %>'); 

귀하의 HTML보기 부분이어야한다 약속/_appointment.html.erb

+0

예 저는 appointments.js.erb 파일이 있고 다른 코드는 생성 된 인스턴스를 가져 와서 div에 추가합니다. railscasts # 136과 마찬가지로 제안합니다. – Petter

+0

$ ('# appointments'). append ('<% = j render (@appointment) %>'). 나는이 라인이 DIV에 HTML을 주입하고 있다고 가정한다. 그렇다면 HTML partial 'appointment/appointment.html.erb를 실행하기를 원하며 html 뷰 부분이어야합니다. 내 대답을 수정했습니다 –

+0

고마워요! 그것은 부분 초보자의 실수를 명명 한 것이 었습니다 ... – Petter

1

는 방법를 생성 제어부에 도면에 약속/new.html.erb 아닌 부분을 렌더링되기 때문이다.

는 부분 때문에보기 약속/new.html.erb 때문에보기가약속/new.js.erb되어야 스크립트 대응 을 정의한다.

+0

"create.js.erb"의 이름을 "new.js.erb"로 변경하면이 오류가 발생합니다. 10ms에서 500 내부 서버 오류를 완료했습니다. ActionView :: MissingTemplate (누락 된 템플릿 약속/create, application/create를 {: locale => [: en], : formats => [: js, : html] "/ 사용자/gjores/사이트/레일/verkstad_test/app/views" ) : app/controllers/appointments_controller.rb : 16 : create에서 : ' – Petter

+0

본인의 경로를 보지 않았습니다. 이것은 현재 라우팅 문제로 보입니다. –

+0

이 내 경로로 업데이트되었습니다 ... – Petter