Skip to content

Instantly share code, notes, and snippets.

@lunalium
Forked from mharris717/Gemfile
Created February 2, 2016 04:07
Show Gist options
  • Save lunalium/67ec249af060627fce8a to your computer and use it in GitHub Desktop.
Save lunalium/67ec249af060627fce8a to your computer and use it in GitHub Desktop.

Revisions

  1. @mharris717 mharris717 revised this gist Aug 19, 2013. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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'
  2. @mharris717 mharris717 revised this gist Aug 19, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    Stuff
    Minimal Paginaton Example (Rails + Ember)
  3. @mharris717 mharris717 revised this gist Aug 19, 2013. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions posts.handlebars
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    {{#each post in controller}}
    {{render post post}}
    {{/each}}

    <a href="#" {{action showMore}}>Show More</a><br>
  4. @mharris717 mharris717 revised this gist Aug 19, 2013. 2 changed files with 6 additions and 13 deletions.
    13 changes: 0 additions & 13 deletions pagination_controller_mod.rb
    Original file line number Diff line number Diff line change
    @@ -1,13 +0,0 @@
    module PaginationControllerMod
    def collection
    #super.paginate(:page => (params[:page] || 1), :per_page => 1)
    @coll ||= end_of_association_chain.paginate(:page => (params[:page] || 1), :per_page => 5)
    end
    def index

    render :json => collection
    end
    def default_serializer_options
    {:meta => {:total_pages => collection.total_pages, :page => (params[:page] || 1).to_i}}
    end
    end
    6 changes: 6 additions & 0 deletions posts_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    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
  5. @mharris717 mharris717 revised this gist Aug 19, 2013. 3 changed files with 38 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions main.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    App.Store = DS.Store.extend
    revision: 11
    adapter: 'Em.PaginationAdapter'
    22 changes: 22 additions & 0 deletions pagination.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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'

    13 changes: 13 additions & 0 deletions pagination_controller_mod.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    module PaginationControllerMod
    def collection
    #super.paginate(:page => (params[:page] || 1), :per_page => 1)
    @coll ||= end_of_association_chain.paginate(:page => (params[:page] || 1), :per_page => 5)
    end
    def index

    render :json => collection
    end
    def default_serializer_options
    {:meta => {:total_pages => collection.total_pages, :page => (params[:page] || 1).to_i}}
    end
    end
  6. @mharris717 mharris717 created this gist Aug 19, 2013.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Stuff