
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
acts_as_commentable_with_replies
Advanced tools
Acts As Commentable With Replies is a Ruby Gem specifically written for Rails/ActiveRecord models. The main goals of this gem are:
Add this line to your application's Gemfile:
gem 'acts_as_commentable_with_replies'
And then execute:
$ bundle
Or install it yourself as:
$ gem install acts_as_commentable_with_replies
Acts As Commentable With Replies uses a comments table to store all comments. To generate migration, model just use.
rails generate acts_as_commentable_with_replies:migration
rake db:migrate
You will get a performance increase by adding in cached columns to your model's tables. You will have to do this manually through your own migrations. See the caching section of this document for more information.
class Post < ActiveRecord::Base
acts_as_commentable
end
@post = Post.new(:title => 'my post!')
@post.save
@post.comment(:commenter => @user, :message => 'hello this is my comment!')
@post.comments.size # => 1
You can also use it as a reply system in comments
@comment = Comment.find(1)
@post.comment(:commenter => @user, :message => 'nice!', :parent => @comment)
class User < ActiveRecord::Base
acts_as_commenter
end
@post = Post.find(1)
@user = User.find(1)
@user.comment(:commentable => @post, :message => 'Comment posted through Commenter')
# to check whether or not user has posted comment on it
@post.commented_by?(@user)
#or
@user.commented_on?(@post)
# to get the list of root comments, not replies
@post.root_comments
To speed up performance you can add cache columns to your commentable model's table. These columns will automatically be updated after each comment. For example, if we wanted to speed up @post we would use the following migration:
class AddCachedCommentsToPosts < ActiveRecord::Migration
def self.up
add_column :posts, :cached_comments_total, :integer, :default => 0
add_index :posts, :cached_comments_total
end
def self.down
remove_column :posts, :cached_comments_total
end
end
Don't know. Haven't decided yet.
Thank you guys! Without you I don't know if it was possible or not!
git checkout -b my-new-feature
)git commit -am 'Added some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that acts_as_commentable_with_replies demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.