diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index f6826f26..185a3bbe 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -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 diff --git a/app/views/static/index.html.haml b/app/views/static/index.html.haml index dc05a5e3..eefe36a5 100644 --- a/app/views/static/index.html.haml +++ b/app/views/static/index.html.haml @@ -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 diff --git a/app/views/user/show.html.haml b/app/views/user/show.html.haml index 7df07969..88e11535 100644 --- a/app/views/user/show.html.haml +++ b/app/views/user/show.html.haml @@ -43,6 +43,13 @@ .hidden-xs= render 'shared/links' .col-md-9.col-xs-12.col-sm-9 = render 'shared/questionbox' - - @answers.each do |a| - = render 'shared/answerbox', a: a + #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' diff --git a/app/views/user/show.js.erb b/app/views/user/show.js.erb new file mode 100644 index 00000000..572ae837 --- /dev/null +++ b/app/views/user/show.js.erb @@ -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 %> \ No newline at end of file