Ajax - 为什么我的远程rails不能形成exucuting create.js.erb?

时间:2016-05-02 11:18:33

标签: javascript ruby-on-rails ajax ruby-on-rails-4

我每次尝试发表评论时都会收到此错误,但是当我刷新显示的评论时会显示

HTTP500:服务器错误 - 服务器遇到意外情况,导致服务器无法完成请求。 (XHR):POST - http://website.com/posts/37/comments

在Chrome中我得到了

无法加载资源:服务器响应状态为500(内部服务器错误)

在我的评论控制器中

if @comment.save
      respond_to do |format|
        format.html do
          flash[:success] = 'Comment posted.'
        end
        format.js # JavaScript response
      end
    end

我将表单设置为remote:true

所以它应该在create.js.erb中执行代码

console.log('working?')
alert('working?')

评论工作正常,但format.js不是

继承人追踪

ActionView::Template::Error (undefined local variable or method `comment' for #<#<Class:0x007f3db84dd300>:0x007f3db9aff0e8>
Did you mean?  @comment):
    1: console.log('done')
    2: alert('done?')
    3: //$('comment-<%= comment.parent.id unless comment.parent.blank? %><%= "-".html_safe  unless comment.parent.blank? %><%= comment.id %>').load(location.href + " comment-<%= comment.parent.id unless comment.parent.blank? %><%= "-".html_safe  unless comment.parent.blank? %><%= comment.id %>");
    4: //$('comment-<%= comment.parent.id unless comment.parent.blank? %><%= "-".html_safe  unless comment.parent.blank? %><%= comment.id %>').html('<% j (render 'comments') %>')
    5: //console.log(comment.parent.id unless comment.parent.blank? %><%= "-".html_safe  unless comment.parent.blank? %><%= comment.id %>)
  app/views/comments/create.js.erb:3:in `_app_views_comments_create_js_erb___4383133957853497951_69951529166680'
  app/controllers/comments_controller.rb:21:in `create'


  Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (3.8ms)
  Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (1.4ms)
  Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb (72.2ms)

0 个答案:

没有答案