module CommentsShared

Public Instance Methods

find_resource() click to toggle source

To find resource of the comments

# File app/controllers/concerns/comments_shared.rb, line 17
def find_resource
  assoc = params[:controller].split('/',2).first
  @resource = current_user.send(assoc).find(params["#{assoc.singularize}_id".to_sym])
end
index() click to toggle source

To find Root Comments ofthe resource restrict display to 4 comments.

# File app/controllers/concerns/comments_shared.rb, line 8
def index
  @comments = @resource.root_comments.order("id DESC").offset(4).includes(:user, :attachments).reverse
  respond_to do |format|
    format.js {render 'comments/show_more'}
  end
end