在Ajax请求轨刚开500内部服务器错误 [英] Gettin 500 Internal Server Error in rails on ajax request

查看:114
本文介绍了在Ajax请求轨刚开500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个表单记录。我用railscast 136作为基础工作。当我试图提交我得到一个500错误缺少的部分。我创建控制器相关的JavaScript的看法,但它要求使用相同的名称作为模型视图。

错误信息

  

渲染约会/ create.js.erb(3.8ms)已完成500内部   在12ms的服务器错误

     

而ActionView ::模板::错误(缺少部分预约/预约   与{:区域设置=> [:EN]:格式=> [:JS,:HTML]:处理程序=> [:雇员再培训局,   :建设者,:咖啡]}。搜查:*   /用户/ gjores /网站/ Rails的/ verkstad_test / APP /意见):       1:$('#约会'),追加('<%= j的渲染(@appointment)%>);应用程序/视图/约会/ create.js.erb:1:    _app_views_appointments_create_js_erb ___ 2325925946390315228_70273089113920   应用程序/控制器/ appointments_controller.rb:16:在创建

控制器

 高清创建
    @appointment = Appointment.new(PARAMS [:预约])
    如果@ appointment.save
      respond_to代码做|格式|
        的format.html {redirect_to时new_appointment_path,:通知=> 成功创建约会。 }
        format.js
      结束
    其他
      渲染:行动=> '新'
    结束
  结束
 

预约/ new.html.erb

 < D​​IV ID =约会>
    <%=渲染'共享/ appointment_part%>
< / DIV>
<%标题为新建约会%>
<表>
<%@ students.each做| S | %>
<%=的form_for @appointment,:远程=>真做| F |%GT;
  &其中;%= f.error_messages%GT;
  &其中; TR>
    &其中; TD>&其中;%= s.name%GT;&所述; / TD>
    < TD><%= f.label:每周%GT;< / TD>
    < TD><%= f.number_field:每周%GT;< / TD>
    &其中; TD>&其中;%= f.label:teacher_id%GT;&所述; / TD>
    < TD><%= f.collection_select(:teacher_id,Teacher.all,:ID,:名)%>< / TD>
    <%= f.hidden_​​field:STUDENT_ID,:价值=> s.id%>

  &其中; TD>&其中;%= f.submit%GT;&所述; / TD>
  < / TR>
<%结束%GT;
<%结束 - %GT;
< /表>

< P><%=的link_to返回列表,appointments_path%>< / P>
 

预约/ create.js.erb

  $('#约会'),追加('<%= j的渲染(@appointment)%>');
 

路线

 约会GET /appointments(.:format)任命#指数
                 POST /appointments(.:format)任命#创建
 new_appointment GET /appointments/new(.:format)任命#新
edit_appointment GET /appointments/:id/edit(.:format)任命#编辑
     预约GET /appointments/:id(.:format)任命#秀
                 PUT /appointments/:id(.:format)任命#更新
                 DELETE /appointments/:id(.:format)任命#销毁
        教师GET /teachers(.:format)教师#指数
                 POST /teachers(.:format)教师#创建
     new_teacher GET /teachers/new(.:format)教师#新
    edit_teacher GET /teachers/:id/edit(.:format)教师#编辑
         老师GET /teachers/:id(.:format)教师#秀
                 PUT /teachers/:id(.:format)教师#更新
                 DELETE /teachers/:id(.:format)教师#销毁
 notice_students POST /students/notice(.:format)学生#通知
        学生获得/students(.:format)学生#指数
                 POST /students(.:format)学生#创建
     new_student GET /students/new(.:format)学生#新
    edit_student GET /students/:id/edit(.:format)学生#编辑
         学生GET /students/:id(.:format)学生#秀
                 PUT /students/:id(.:format)学生#更新
                 DELETE /students/:id(.:format)学生#销毁
 

解决方案

您的堆栈跟踪显示

 缺少的部分预约/预约
 

所以看起来Rails是试图呈现一个部分叫约会/ appointments.html或约会/ appointments.js

难道一个名为appointments.js.erb或appointments.html.erb存在?

如果没有,那么创建它。

然而,我怀疑你正在尝试做的是显示您担任我想你想低于code更新一些元素的HTML页面上

  $('#约会'),追加('<%= j的渲染(@appointment)%>');
 

我想你需要这条线为红色

  $('#约会'),追加('<%= j的渲染:部分=>预约/预约,:格式=>:HTML%> ');
 

您的HTML视图部分应该是约会/ _appointment.html.erb

I'm trying to create a record from a form. I've used railscast 136 as ground work. When I trying to submit I get a 500 error for missing partial. I've created the controller correlated javascript view but it is requesting a view with the same name as the model.

error message

Rendered appointments/create.js.erb (3.8ms) Completed 500 Internal Server Error in 12ms

ActionView::Template::Error (Missing partial appointments/appointment with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/gjores/Sites/Rails/verkstad_test/app/views" ): 1: $('#appointments').append('<%= j render(@appointment) %>'); app/views/appointments/create.js.erb:1:in _app_views_appointments_create_js_erb___2325925946390315228_70273089113920' app/controllers/appointments_controller.rb:16:increate'

Controller

 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

appointments/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>

appointments/create.js.erb

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

Routes

    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

解决方案

Your stack trace shows

Missing partial appointments/appointment

So it looks like rails is trying to render a partial called appointments/appointments.html or appointments/appointments.js

Does a file called appointments.js.erb or appointments.html.erb exist?

If not then create it.

I however suspect that what you are trying to do is show your appointment as I think you want the code below to update the html of some element on your page

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

I think you need this line to red

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

Your html view partial should be appointments/_appointment.html.erb

这篇关于在Ajax请求轨刚开500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆