Bergrebell / CyberCoach

1 stars 1 forks source link

iterator for resources / rails pagination integration #23

Closed lexruee closed 9 years ago

lexruee commented 9 years ago

I created a simple example for pagination. See users_controller.rb:

    page = request.query_parameters[:page].nil? ? 1 : request.query_parameters[:page]
    page = page.to_i
    size = 5
    @users = RestAdapter::User.all query: { size: size, start: (page-1)*size }
    pages = (RestAdapter::User.available / size.to_f).ceil
    @links =  (1..pages)

Can this be done in a much more elegant way?

lexruee commented 9 years ago

Some teams put lot of garbage data on the cyber coach server. So this topic must be solved.

wanze commented 9 years ago

Hi Alex, As we consider only users that are subscribed to our app, this should not be a huge problem, what do you think? Also for friend requests, we can grab the user from our DB.

lexruee commented 9 years ago

@wanze It is the simplest solution, here we could use the gem will_paginate. I was thinking of integrating the gem will_paginate into our Facade::BaseFacade class.

lexruee commented 9 years ago

@wanze What do you think of this commit? e975c556e1ea352bee0e9bd20b306b72c44a36e0

Controller:

@users = Facade::User.paginate(:page => params[:page], :per_page => 5)

View:

<%= will_paginate @users %>
lexruee commented 9 years ago

Commit 7cc70098c566d0e9dde8b7709de51bbe18635cde closes this issue #23.