elight / acts_as_commentable_with_threading

Similar to acts_as_commentable; however, utilizes awesome_nested_set to provide threaded comments
MIT License
672 stars 167 forks source link

On index page #113

Closed dcalixto closed 6 years ago

dcalixto commented 6 years ago

After setup the gem on show action i placed the new_comment to index action on Posts

   def index
    @posts = Post.all
    @new_comment    = Comment.build_from(@post, current_user.id, "")
  end

And added to the view

<div class="post">
<% @posts.each do |post| %>

   <p class="listText">
    <%= post.body %>              
    </p>

<div class="row">
    <%= render partial: "comments/template", locals: {commentable: post, new_comment: @new_comment} %>
    </div>
</div>

Rails show the undefined method error

NameError in CommentsController#create wrong constant name

 def create
    @post = Post.find_by(params[:id])
    commentable = commentable_type.constantize.find(commentable_id)
    **@comment = Comment.build_from(commentable, current_user.id, body)**

    respond_to do |format|
      if @comment.save
        make_child_comment
        format.html  { redirect_to(@post, :notice => 'Comment was successfully added.') }
      else
        format.html  { render :action => "new" }
      end
    end

end

My doubt is to render and comment with acts_as_commentable_with_threading on index is just by ajax?