Rails评论Ajax

I've scoured the web All day looking for a solution to this problem. A lot of people on stack overflow have had the same issue, and I've tried all of their solutions, yet it doesn't seem to be working for me so I thought I'd give it a shot here. I'm just trying to get my page to update my comments after posting without refreshing. The problem seems to lie in my create.js.erb file, as it doesn't seem to be registering at all. Here's what I've got so far.

The Controller:

class CommentsController < ApplicationController

    def create

    @content = params[:content]

    @comment = Comment.create(:video_id => params[:video_id], :content => params[:content])

    @video = Video.find(params[:video_id])

    respond_to do |format| 

    format.html {redirect_to "/videos/#{@video.id}", flash:{success_comment: "created!"}}

    format.js {}

    end

  end

end

The Create Comment Form:

  <%= form_tag "/videos/#{@video.id}/comments", :method => "post", :remote => true do %>
    <%=label_tag :comment, nil %>

    <%=text_area_tag :content, nil, class: "commentinput" %>

    <%=submit_tag "Comment"%>

  <% end %>

The app/views/comments/create.js.erb:

$('.comments').append('<%= escape_javascript(render :partial => @comment) %>');

$('.commentinput').val('')

Could someone please tell me what I am missing here??? Thanks in advance.

Rails says when using remote: true on form_tag, you will need this little snippet of code tailored to your elements/application naturally. Have you tried that?

$ ->
  $("a[data-remote]").on "ajax:success", (e, data, status, xhr) ->
    alert "The article was deleted."

Any error messages on your Rails server terminal window, or in your log file?...

Tweak your create.js.erb file to test it:

$('.comments').append('<%= escape_javascript(render :text => 'the create.js.erb file seems to work') %>');

...which should add that text under each of your comments, and demonstrate the general structure of the code is working fine (if not... something else is wrong!).

Then, look at the syntax of the render function - is there a _comment.html.haml (or .erb) partial that will draw a single comment row? If so, you should be able to change your line to be:

$('.comments').append('<%= escape_javascript(render :partial => 'comment') %>');

or

$('.comments').append('<%= escape_javascript(render @comment) %>');