D
D
dexdev2013-12-10 20:40:31
Ruby on Rails
dexdev, 2013-12-10 20:40:31

How to make tree comments with the acts_as_commentable gem?

I use rails 4 and ruby ​​2.0.0
Installed the gem 'acts_as_commentable' everything went fine, registered

class Post < ActiveRecord::Base
  
  acts_as_commentable
end

Created a controller
class CommentsController < ApplicationController


  def create
      comment = Comment.new comment_params
      commentable = params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id])
      comment.commentable = commentable
      comment.user = current_user

      comment.save
      redirect_to [commentable.user, commentable]
    end


    private

    def comment_params
        params.require(:comment).permit!
    end
end

added to the view:
<%= form_for(Comment.new) do |f| %>

<div class="row">
    <div class="large-1 columns">
    </div>

    <div class="large-11 columns text-left">

            <%= form_tag "/posts/add_new_comment" do %>
    <%= hidden_field_tag "id", post.id %>
    <%= text_area_tag "comment[comment]" %>
    <%= submit_tag "Post Comment" %>
  <% end %>

like www.arailsdemo.com/posts/16 but there is a post from 2010, and rails complain about undefined method `pending?' for #

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arkady Butermanov, 2013-12-11
@Arkadey

Try modifying this gem for tree comments:
https://github.com/elight/acts_as_commentable_with...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question