Skip to content

Instantly share code, notes, and snippets.

@mharris717
Last active February 2, 2016 04:07
Show Gist options
  • Save mharris717/6275219 to your computer and use it in GitHub Desktop.
Save mharris717/6275219 to your computer and use it in GitHub Desktop.
Minimal Pagination Example (Rails + Ember)

Minimal Paginaton Example (Rails + Ember)

ruby '1.9.3'
source 'https://rubygems.org'
gem 'rails', '3.2.13'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'pg'
gem 'active_model_serializers'
gem 'will_paginate'
App.Store = DS.Store.extend
revision: 11
adapter: 'Em.PaginationAdapter'
DS.Model.reopenClass
loadMore: ->
page = DS.defaultStore.typeMapFor(@).metadata.page + 1
@find(page: page)
Em.ArrayController.reopen
modelClass: ->
@$firstObject.constructor
showMore: ->
@modelClass().loadMore()
serializer = DS.RESTSerializer.create()
Em.PaginationAdapter = DS.RESTAdapter.reopen
serializer: serializer
serializer.configure
total: 'total'
last_dt: 'last_dt'
total_pages: 'total_pages'
page: 'page'
{{#each post in controller}}
{{render post post}}
{{/each}}
<a href="#" {{action showMore}}>Show More</a><br>
class PostsController < ApplicationController
def index
@posts = Post.all.paginate(:page => (params[:page] || 1), :per_page => 5)
render :json => @posts, :meta => {:total_pages => collection.total_pages, :page => (params[:page] || 1).to_i}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment