added pagination to answers
This commit is contained in:
parent
f53ca1b449
commit
81becddbd5
|
@ -1,6 +1,10 @@
|
||||||
class QuestionController < ApplicationController
|
class QuestionController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@question = Question.find(params[:id])
|
@question = Question.find(params[:id])
|
||||||
@answers = @question.answers.reverse_order
|
@answers = @question.answers.reverse_order.paginate(page: params[:page])
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.js
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,12 @@
|
||||||
- @answers.each do |a|
|
- @answers.each do |a|
|
||||||
= render 'shared/answerbox', a: a, show_question: false
|
= render 'shared/answerbox', a: a, show_question: false
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
- if user_signed_in? and !current_user.answered? @question and current_user != @question.user
|
- if user_signed_in? and !current_user.answered? @question and current_user != @question.user
|
||||||
.panel.panel-default#q-answer-box
|
.panel.panel-default#q-answer-box
|
||||||
.panel-heading
|
.panel-heading
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
$('#answers').append('<% @answers.each do |answer|
|
||||||
|
%><%= j render 'shared/answerbox', a: answer, show_question: false
|
||||||
|
%><% end %>');
|
||||||
|
<% if @answers.next_page %>
|
||||||
|
$('#pagination').html('<%= j will_paginate @answers, renderer: BootstrapPagination::Rails, page_links: false %>');
|
||||||
|
<% else %>
|
||||||
|
$('#pagination, #load-more-btn').remove();
|
||||||
|
<% end %>
|
Loading…
Reference in New Issue