diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 32d0229f..52351d6b 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -36,4 +36,10 @@ class UserController < ApplicationController @type = :friend render 'show_follow' end + + def questions + @title = 'Questions' + @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first + @questions = @user.questions.reverse_order.paginate(page: params[:page]) + end end diff --git a/app/views/user/questions.html.haml b/app/views/user/questions.html.haml new file mode 100644 index 00000000..d6ae7e05 --- /dev/null +++ b/app/views/user/questions.html.haml @@ -0,0 +1,17 @@ +.profile--header +.container.j2-page + .col-md-3.col-xs-12.col-sm-3 + = render 'user/profile_info' + .hidden-xs= render 'shared/links' + .col-md-9.col-xs-12.col-sm-9 + %h1.j2-lh= @title + #questions + - @questions.each do |a| + = render 'shared/answerbox', a: a + + #pagination= will_paginate @questions, renderer: BootstrapPagination::Rails, page_links: false + + - if @questions.next_page + %button#load-more-btn.btn.btn-default{type: :button, data: { current_page: @questions.current_page }} + Load more + .visible-xs= render 'shared/links' diff --git a/app/views/user/questions.js.erb b/app/views/user/questions.js.erb new file mode 100644 index 00000000..f648a149 --- /dev/null +++ b/app/views/user/questions.js.erb @@ -0,0 +1,8 @@ +$('#questions').append('<% @questions.each do |a| + %><%= j render 'shared/answerbox', a: a +%><% end %>'); +<% if @questions.next_page %> +$('#pagination').html('<%= j will_paginate @questions, renderer: BootstrapPagination::Rails, page_links: false %>'); +<% else %> +$('#pagination, #load-more-btn').remove(); +<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6e268567..663b0705 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,4 +71,5 @@ Rails.application.routes.draw do match '/:username/q/:id', to: 'question#show', via: 'get', as: :show_user_question_alt match '/:username/followers(/p/:page)', to: 'user#followers', via: 'get', as: :show_user_followers_alt, defaults: {page: 1} match '/:username/friends(/p/:page)', to: 'user#friends', via: 'get', as: :show_user_friends_alt, defaults: {page: 1} + match '/:username/questions(/p/:page)', to: 'user#questions', via: 'get', as: :show_user_questions, defaults: {page: 1} end