Note that there are some explanatory texts on larger screens.

plurals
  1. POActs as commentable with threading example
    primarykey
    data
    text
    <p>I'm new to Rails and am currently developing a blog. I want to know if there is a tutorial on how to use Acts as commentable with threading, since the only instructions to use from the GitHub are to add <code>acts_as_commentable</code> to your model.</p> <ol> <li>How should I create the form for new comments?</li> <li>How can I retrieve all the comments from a model?</li> <li>How do I configure the routes in order to show comments?</li> <li>How do I modify my controllers to make this feature available?</li> </ol> <p></p> <pre><code>class Comment &lt; ActiveRecord::Base acts_as_nested_set :scope =&gt; [:commentable_id, :commentable_type] #attr_accessible :commentable, :body, :user_id 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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload