added pagination to User#show

This commit is contained in:
nilsding 2014-12-08 15:23:04 +01:00
parent cc87061fe2
commit 293837984e
4 changed files with 22 additions and 3 deletions

View File

@ -2,6 +2,10 @@ class UserController < ApplicationController
def show
@user = User.find_by_screen_name!(params[:username])
@answers = @user.answers.reverse_order.paginate(page: params[:page])
respond_to do |format|
format.html
format.js
end
end
def edit

View File

@ -44,7 +44,7 @@
#pagination= will_paginate @timeline, renderer: BootstrapPagination::Rails, page_links: false
- if @timeline.next_page
%button#load-more-btn.btn.btn-default{type: :button, 'data-current-page' => @timeline.current_page, 'data-type' => 'timeline'}
%button#load-more-btn.btn.btn-default{type: :button, 'data-current-page' => @timeline.current_page}
Load more
.visible-xs= render 'shared/links'
- else

View File

@ -43,6 +43,13 @@
.hidden-xs= render 'shared/links'
.col-md-9.col-xs-12.col-sm-9
= render 'shared/questionbox'
#answers
- @answers.each do |a|
= render 'shared/answerbox', a: a
#pagination= will_paginate @answers, renderer: BootstrapPagination::Rails, page_links: false
- if @answers.next_page
%button#load-more-btn.btn.btn-default{type: :button, 'data-current-page' => @answers.current_page}
Load more
.visible-xs= render 'shared/links'

View File

@ -0,0 +1,8 @@
$('#answers').append('<% @answers.each do |a|
%><%= j render 'shared/answerbox', a: a
%><% end %>');
<% if @answers.next_page %>
$('#pagination').html('<%= j will_paginate @answers, renderer: BootstrapPagination::Rails, page_links: false %>');
<% else %>
$('#pagination, #load-more-btn').remove();
<% end %>