Answer the question
In order to leave comments, you need to log in
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
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
<%= 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 %>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question