Rails的will_paginate gem是项目与angular.js做分页 [英] Rails will_paginate gem with angular.js to do pagination
问题描述
语境:我有一个Rails后端作为一个API来的Angular.JS前端应用
Context: I have a Rails backend serving as an API to an Angular.JS front-end application.
任务:我想检索所有的不同的物种从Rails的后端恐龙的记录。由于有超过500条记录,我想在同一时间只能得到30种。
Task: I want to retrieve all of the records of different species of "dinosaurs" from the Rails backend. Since there are over 500 records, I want to only get 30 species at a time.
我目前的做法:我使用的是will_paginate gem是项目中的dinosaurs_controller我的Rails指数控制器操作。我有它运行的是这样的。
My current approach: I am using the will_paginate gem in my Rails index controller action for the dinosaurs_controller. I have it running like this.
def index
@dinosaurs = Dinosaur.paginate(:page => params[:page], :per_page => 30)
end
在我的角度code:
我有一个名为DinoApp模块,并正在使用ngresource创建一个入口资源
I have a module called DinoApp and am using ngresource to create an Entry resource
app = angular.module("DinoApp", ["ngResource"])
app.factory "Entry", ["$resource", ($resource) ->
$resource("/api/v1/dinosaurs/:id", {id: "@id"}, {update: {method: "PUT"}} )
]
我的角器看起来是这样的:
My Angular controller looks like this:
@MainController = ["$scope", "Entry", ($scope, Entry) ->
$scope.entries = Entry.query({page: 1})
$scope.viewPost = (dinosaurId) ->
]
code这条线就按API在dinosaurs_controller的索引操作,只会一次返回30种恐龙的:
This line of code would hit the API at dinosaurs_controller's index action and will only return 30 species of "dinosaurs" at a time:
$scope.entries = Entry.query({page: 1})
现在 - 我怎么才能angular.js表现出翻页键和翻页追加到视图
Now - how would I get angular.js to show a next page button and append the next page to the view?
推荐答案
我创建了这个指令,它可能会有所帮助:
I created a directive for this, which might be helpful:
https://github.com/heavysixer/angular-will-paginate
这篇关于Rails的will_paginate gem是项目与angular.js做分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!