Jquery RubyonRails ajax错误
我尝试使用rails远程表单方法提交表单,它正确调用数据并正确发送到数据库并存储,但当我尝试以html获取响应时,它在Jquery中显示引用错误 轨道形式:Jquery RubyonRails ajax错误,jquery,ruby-on-rails,ruby,ajax,coffeescript,Jquery,Ruby On Rails,Ruby,Ajax,Coffeescript,我尝试使用rails远程表单方法提交表单,它正确调用数据并正确发送到数据库并存储,但当我尝试以html获取响应时,它在Jquery中显示引用错误 轨道形式: <%= form_for(@comment,remote: true) do |f| %> <%= f.hidden_field :song_id, value: @song.id %> <%= f.text_area :comment, class: "
<%= 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
def创建
参数[:comment][:user\u id]=当前的\u user.id
@comment=comment.new(comment_参数)
if@comment.save
内联渲染:''.html\u安全
其他的
render inline:“抱歉,出现问题,请重试:)”.html\u安全
结束
结束
咖啡剧本
$(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>"
$(文档).ready->
$(“#新的#u评论”)。关于(“ajax:success”,(e,数据,状态,xhr)->
console.log数据
$(“#注释显示”)。追加xhr.responseText
$(“#注释”).val(“”)
$('#comment_count').html(parseInt($('#comment_count').text())+1)
).on“ajax:error”(e,xhr,status,error)->
console.log错误
$(“#注释显示”)。附加“错误”
它打印ajax:错误部分
我在这方面做错了什么?
请帮助,谢谢您可以尝试将“内联”替换为“文本”
render text: '<li><%= @comment.comment %></li>'.html_safe
呈现文本:''.html\u安全
您可以尝试将“内联”替换为“文本”
render text: '<li><%= @comment.comment %></li>'.html_safe
呈现文本:''.html\u安全
它正在打印,因为它不是@comment.comment的值。它正在打印,因为它不是@comment.comment的值