Minimal Paginaton Example (Rails + Ember)
Last active
February 2, 2016 04:07
-
-
Save mharris717/6275219 to your computer and use it in GitHub Desktop.
Minimal Pagination Example (Rails + Ember)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Store = DS.Store.extend | |
revision: 11 | |
adapter: 'Em.PaginationAdapter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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