From f93624fa2cab0753e5809ffe7cb2edf3007ca60c Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 12 Jan 2015 06:57:43 +0100 Subject: [PATCH] added groups route thing --- app/controllers/user_controller.rb | 11 +++++++++++ app/views/user/groups.html.haml | 14 ++++++++++++++ config/routes.rb | 1 + 3 files changed, 26 insertions(+) create mode 100644 app/views/user/groups.html.haml diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index f4913875..70b6f15d 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -46,6 +46,17 @@ class UserController < ApplicationController end # endregion + # region Groups + def groups + @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! + @groups = if current_user == @user + @user.groups.all + else + @user.groups.where(private: false).all + end + end + # endregion + def followers @title = 'Followers' @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! diff --git a/app/views/user/groups.html.haml b/app/views/user/groups.html.haml new file mode 100644 index 00000000..5b1fe965 --- /dev/null +++ b/app/views/user/groups.html.haml @@ -0,0 +1,14 @@ +.profile--header +.container.j2-page + .col-md-3.col-xs-12.col-sm-4 + = render 'user/profile_info' + .hidden-xs= render 'shared/links' + .col-md-9.col-xs-12.col-sm-8 + %h1.j2-lh.hidden-xs Groups + %h1.visible-xs Groups + + %ul + - @groups.each do |group| + %li= group.title + + .visible-xs= render 'shared/links' diff --git a/config/routes.rb b/config/routes.rb index 8ae75153..7c07be4e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,6 +89,7 @@ Rails.application.routes.draw do match '/@:username/q/:id', to: 'question#show', via: 'get', as: :show_user_question match '/@:username/followers(/p/:page)', to: 'user#followers', via: 'get', as: :show_user_followers, defaults: {page: 1} match '/@:username/friends(/p/:page)', to: 'user#friends', via: 'get', as: :show_user_friends, defaults: {page: 1} + match '/@:username/groups(/p/:page)', to: 'user#groups', via: 'get', as: :show_user_groups, defaults: {page: 1} match '/:username(/p/:page)', to: 'user#show', via: 'get', as: :show_user_profile_alt, defaults: {page: 1} match '/:username/a/:id', to: 'answer#show', via: 'get', as: :show_user_answer_alt match '/:username/q/:id', to: 'question#show', via: 'get', as: :show_user_question_alt