Javascript Ajax-为什么不是&x27;我的远程rails表单EXUCTING create.js.erb吗?
每次尝试发布评论时都会出现此错误,尽管刷新页面时会显示评论 HTTP500:服务器错误-服务器遇到意外情况,无法满足请求。 (XHR):POST- 我用铬合金做的 加载资源失败:服务器响应状态为500(内部服务器错误) 在我的评论中Javascript Ajax-为什么不是&x27;我的远程rails表单EXUCTING create.js.erb吗?,javascript,ruby-on-rails,ajax,ruby-on-rails-4,Javascript,Ruby On Rails,Ajax,Ruby On Rails 4,每次尝试发布评论时都会出现此错误,尽管刷新页面时会显示评论 HTTP500:服务器错误-服务器遇到意外情况,无法满足请求。 (XHR):POST- 我用铬合金做的 加载资源失败:服务器响应状态为500(内部服务器错误) 在我的评论中 if @comment.save respond_to do |format| format.html do flash[:success] = 'Comment posted.' end
if @comment.save
respond_to do |format|
format.html do
flash[:success] = 'Comment posted.'
end
format.js # JavaScript response
end
end
我将表单设置为远程: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)
ActionView::Template::Error(未定义的局部变量或方法'comment')#
你是说?@评论):
1:console.log('done')
2:警报(“完成”)
3://$('comment-').load(location.href+“comment-”);
4://$('comment-').html(“”)
5://console.log(comment.parent.id,除非comment.parent.blank?%>)
app/views/comments/create.js.erb:3:in`_app_views_comments_create_js_erb__4383133957853; 53497951_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\u dispatch/middleware/templates/rescues//u trace.text.erb(3.8ms)
Rendered/usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action\u dispatch/middleware/templates/rescues//u request\u and\u response.text.erb(1.4ms)
Rendered/usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action\u dispatch/middleware/templates/rescues/template\u error.text.erb(72.2ms)
你能发布完整的堆栈跟踪吗?错误页面不显示,我在控制台中找到了它,因为它的遥控器我看不到跟踪。还有其他方法可以看到痕迹吗?[初学者]您可以在Rails日志中看到跟踪。在开发中,它将位于/path/to/app/log/development.log.Inenvironments/production.rb
,注释掉config.confirm\u all\u requests\u local=false
,或者您可以检查log/production.log
是否可以发布完整的堆栈跟踪?错误页面不会显示,我把它放在控制台里,因为它是遥控器,我看不到痕迹。还有其他方法可以看到痕迹吗?[初学者]您可以在Rails日志中看到跟踪。在开发过程中,它将位于/path/to/app/log/development.log.Inenvironments/production.rb
,注释掉config.confirm\u all\u requests\u local=false
,或者您可以检查log/production.log