1
我试图使用Rails远程形式的方法是调用正确的数据发送到数据库中正确地存储,但是当我试图让HTML的响应它显示在jQuery的Ruby on Rails的Ajax错误
参考错误提交表单导轨形式:
<%= form_for(@comment,remote: true) do |f| %>
<%= f.hidden_field :song_id, value: @song.id %>
<%= f.text_area :comment, class: "form-control col-8", placeholder: "comment", id: "comment", :required => true %>
<%= f.submit "post", id: "comment_post", class: "btn btn-primary col-4" %>
<% end %>
控制器这样的:
def create
params[:comment][:user_id] = current_user.id
@comment = Comment.new(comment_params)
if @comment.save
render inline: '<li><%= @comment.comment %></li>'.html_safe
else
render inline: 'Sorry Something wrong try again pls :)'.html_safe
end
end
咖啡脚本
$(document).ready ->
$("#new_comment").on("ajax:success", (e, data, status, xhr) ->
console.log data
$('#comment_display').append xhr.responseText
$('#comment').val(" ")
$('#comment_count').html(parseInt($('#comment_count').text())+1)
).on "ajax:error", (e, xhr, status, error) ->
console.log error
$("#comment_display").append "<p>ERROR</p>"
它打印AJAX:错误部分
我在这做什么错? 请帮忙谢谢
据印刷,因为它不是值尝试更换“内联” @ comment.comment – Pranavadurai