Devise or similar user authentication system, which provides a
current_usermethod to controllers and views.
Add FlyoverComments to your gemfile:
flyover_comments.rb to your initializers, defining the name of your user class and the method that returns the current user:
FlyoverComments.configure do |config| config.user_class = "User" config.current_user_method = "current_user" end
mount the engine in your routes file:
mount FlyoverComments::Engine, at: "/flyover_comments"
Add comments to your commentable model:
class Post < ActiveRecord::Base belongs_to :user flyover_commentable end
You can the use view helpers to display the comment form and list. In both cases, you need to pass an instance of your
flyover_commentable model to the heper.
To display the new comment form:
<%= flyover_comment_form(@post) %>
To display the list of comments:
<%= flyover_comments_list(@post) %>
In order, FlyoverComments will try the following to display the commenter name:
user#flyover_comments_name. If you want to override what is displayed for the commenter name, add this method to your user class.
user#name- User's name
user#full_name- User's full name
user#email- User's email
Comment creation & deletion authorization
By default, any user can create comments and a user can delete only comments that s/he created. If you want to override this behavior, you can add the following methods to your user class and FlyoverComments will default to them. E.g:
class User def can_delete_flyover_commment?(comment) self.is_admin? || comment.user == self end def can_create_flyover_comment?(comment) !self.is_banned_from_commenting? end end