Skip to content

Instantly share code, notes, and snippets.

@meoooh
Created November 11, 2013 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meoooh/7409088 to your computer and use it in GitHub Desktop.
Save meoooh/7409088 to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
before_action :set_commentable
before_action :set_comment, only: [:show, :update, :destroy]
before_filter :authenticate_user!
def index
obj = {}
params[:page] = (params[:page].to_i.is_a? Integer) ? (params[:page].to_i > 0 ? params[:page].to_i : 1) : 1
@comments = @commentable.comments.page(params[:page])
obj['comments'] = @comments
if @commentable.comments.page(params[:page].to_i + 1).count > 0
obj['next'] = params[:page].to_i + 1
end
render json: obj
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment