title: Rails comments not rendering with ajax
body: <p>I've added ajax comments to my rails app and in the console I see that the comments are going through but rails is not displaying/rendering the comments on the page. My javascript seems to be working fine, I'm not sure where the glitch is</p>
  
  <p><strong>users/show.html.erb</strong></p>
  
  <pre><code>&lt;div class="comments"&gt;
    &lt;h2&gt;Comments&lt;/h2&gt;
    &lt;%= render :partial =&gt; 'comments/form', :locals =&gt; { :comment =&gt; @new_comment } %&gt;
    &lt;%= render :partial =&gt; 'comments/comment', :collection =&gt; @comments, :as =&gt; :comment %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>comments/_comment.html.erb</strong></p>
  
  <pre><code>   &lt;div class="comment"  id="comment-&lt;%= comment.id %&gt;"&gt;
     &lt;hr&gt;
  
      &lt;%= link_to "×", comment_path(comment), :method =&gt; :delete, :remote =&gt; true, :confirm =&gt; "Are you sure you want to remove this comment?", :disable_with =&gt; "×", :class =&gt; 'close' %&gt;
      &lt;h4&gt;
        &lt;%= comment.user.username %&gt;
        &lt;small&gt;
          &lt;%= comment.updated_at %&gt;
        &lt;/small&gt;
      &lt;/h4&gt;
    &lt;p&gt;
      &lt;%= comment.body %&gt;
    &lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>comments/_form.html.erb</strong></p>
  
  <pre><code>&lt;div class="comment-form"&gt;
    &lt;%= simple_form_for comment,:url =&gt; comments_path,  :remote =&gt; true do |f| %&gt;
      &lt;%= f.input :body, :input_html =&gt; { :rows =&gt; "2" }, :label =&gt; false %&gt;
      &lt;%= f.input :commentable_id, :as =&gt; :hidden, :value =&gt; comment.commentable_id %&gt;
      &lt;%= f.input :commentable_type, :as =&gt; :hidden, :value =&gt; comment.commentable_type %&gt;
      &lt;%= f.button :submit, :class =&gt; "", :disable_with =&gt; "Submitting…" %&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>commentsController</strong></p>
  
  <pre><code>def create 
    @comment_hash = params[:comment]
    @obj = @comment_hash[:commentable_type].constantize.find(@comment_hash[:commentable_id])
    # Not implemented: check to see whether the user has permission to create a comment on this object
    @comment = Comment.build_from(@obj, current_user, @comment_hash[:body])
    if @comment.save
      render :partial =&gt; "comments/comment", :locals =&gt; { :comment =&gt; @comment }, :layout =&gt; false, :status =&gt; :created
    else
      render :js =&gt; "alert('error saving comment');"
    end
  
   def destroy
      @comment = Comment.find(params[:id])
      if @comment.destroy
        render :json =&gt; @comment, :status =&gt; :ok
      else
        render :js =&gt; "alert('error deleting comment');"
      end
    end
  </code></pre>
  
  <p><strong>comments.js.coffee</strong></p>
  
  <pre><code>jQuery -&gt;
    # create a comment
    $(".comment-form")
      .on "ajax:beforeSend", (evt, xhr, settings) -&gt;
        $(this).find('textarea')
          .addClass('uneditable-input')
          .attr('disabled', 'disabled');
      .on "ajax:success", (evt, data, status, xhr) -&gt;
        $(this).find('textarea')
          .removeClass('uneditable-input')
          .removeAttr('disabled', 'disabled')
          .val('');
        $(xhr.responseText).hide().insertAfter($(this)).show('slow')
  
        #delete/destroy a comment
        $(document)
      .on "ajax:beforeSend", ".comment", -&gt;
        $(this).fadeTo('fast', 0.5)
      .on "ajax:success", ".comment", -&gt;
        $(this).hide('fast')
      .on "ajax:error", ".comment", -&gt;
        $(this).fadeTo('fast', 1)
  </code></pre>
  
  <p><strong>usersController</strong></p>
  
  <pre><code>def show
    @user = User.find(params[:id])
  
    #@user= User.find_by_username(params[:username])
    @comments = @user.comment_threads.order('created_at desc')
    @new_comment = Comment.build_from(@user, current_user, "")
  end   
  </code></pre>
  
  <h1>UPDATE</h1>
  
  <p><strong>comment model</strong></p>
  
  <pre><code> class Comment &lt; ActiveRecord::Base
    acts_as_nested_set :scope =&gt; [:commentable_id, :commentable_type]
  
    validates :body, :presence =&gt; true
    validates :user, :presence =&gt; true
  
    # NOTE: install the acts_as_votable plugin if you
    # want user to vote on the quality of comments.
    #acts_as_votable
  
    belongs_to :commentable, :polymorphic =&gt; true
  
    # NOTE: Comments belong to a user
    belongs_to :user
  
    # Helper class method that allows you to build a comment
    # by passing a commentable object, a user_id, and comment text
    # example in readme
    def self.build_from(obj, user_id, comment)
      new \
        :commentable =&gt; obj,
        :body        =&gt; comment,
        :user_id     =&gt; user_id
    end
  
    #helper method to check if a comment has children
    def has_children?
      self.children.any?
    end
  
    # Helper class method to lookup all comments assigned
    # to all commentable types for a given user.
    scope :find_comments_by_user, lambda { |user|
      where(:user_id =&gt; user.id).order('created_at DESC')
    }
  
    # Helper class method to look up all comments for
    # commentable class name and commentable id.
    scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id|
      where(:commentable_type =&gt; commentable_str.to_s, :commentable_id =&gt; commentable_id).order('created_at DESC')
    }
  
    # Helper class method to look up a commentable object
    # given the commentable class name and id
    def self.find_commentable(commentable_str, commentable_id)
      commentable_str.constantize.find(commentable_id)
    end
  end
  </code></pre>