Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Hi Chris How do I add jquery and ajax to the comments form from your tutorial?

General • Asked by emmanuel alcime

I wrote some jquery to accomplish this here is the code.




var comment = $("#comment_body").val();
var id = '#{params[:video_id]}';
$("#comment_body").keypress(function(event) {
if (event.which == 13) {
var request = $.ajax({
type:"POST" ,
url: '/videos/comments' ,
data:{ "comment":$(this).val()},
timeout : 5000

  request.success(function() {
          $("#error-information").html("comment has been posted");
  request.error(function(httpObj, textStatus) {       
                window.location ="http://localhost:3000/users/sign_in";
  // Clear out the form so it can be used again    
   $("#comment_body").attr('placeholder', 'Join The discussion...');       



But I keep getting this error from the comments controller?

NoMethodError in CommentsController#create

undefined method `comments' for nil:NilClass
at this line @comment = comment_params
Now can someone tell me exactly what I am doing wrong here?

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.