Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
PeanutGallery adds a simple commenting feature to your Ruby on Rails application.
Add this line to your application's Gemfile:
gem 'peanut_gallery'
And then execute:
$ bundle
Or install it yourself as:
$ gem install peanut_gallery
Next, you'll want to add a Comment
model to your application. You can do this
by running the install generator:
$ bundle exec rails g peanut_gallery:install
This will add a migration, so you'll want to migrate your database.
$ bundle exec rake db:migrate
The install generator adds a
Comment
model to your application. You'll notice the model file has no content, but still works. That's because it is inheriting from thePeanutGallery::Comment
model. This is so we can hide the abstracted (repeated) logic. But, you're welcome to override any default logic in your project'sComment
model.Note: PeanutGallery never accesses the base model by default. It will always look for the
Comment
model in your project.
There are three items to be concerned with to get PeanutGallery working properly:
Running the install generator should add the following to your
config/routes.rb
file:
namespace :peanut_gallery do
resources :comments, :only => [:create, :update, :destroy]
end
If something went wrong and you don't see this, go ahead and add it manually.
For any model that you want to have comments, all you have to do is all
has_comments
to the model. For example, if a Post
model has comments, your
model might look like this:
class Post < ActiveRecord::Base
has_comments
end
This means you can call comments
on any single object within this model.
There is a helper made available to you for rendering a form:
<%= new_comment_form(object, author) %>
Here the object
is the item to which you want to attach the comment. The
author
is the object of the user who is adding the comment.
*Note: PeanutGallery assumes (but does not require) you're using a
User
model, and that the logged in user iscurrent_user
. Therefore, you can leave off theauthor
parameter if you have your current user wrapped up in acurrent_user
method.
In addition to the forms helper, there is also a helper to delete a comment.
<%= delete_comment_link(comment_object) %>
Of course, you can write this manually (or add your own helper) if you'd like to.
PeanutGallery assumes the use of a user model. If you want to override that, you'll need to add the association into your Comment
model:
class Comment < ActiveRecord::Base
belongs_to :author, :class_name => 'YourUserClassName'
end
The controller doing all the work for PeanutGallery is the
PeanutGallery::CommentsController
. If you want to override it, you can create
a controller at app/controllers/peanut_gallery/comments_controller.rb
.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that peanut_gallery 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.