From 3e0e5878e6f8ec4ede466bdcc5688234df2c4dcd Mon Sep 17 00:00:00 2001 From: jomo Date: Sun, 29 Jun 2014 12:21:46 +0200 Subject: [PATCH] better user listing --- app/controllers/users_controller.rb | 8 +++++++- app/views/users/index.html.erb | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4b5af22..8c2c444 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -8,7 +8,13 @@ class UsersController < ApplicationController if params[:role].downcase == "staff" @users = User.all.select {|u| u.role >= Role.get(:mod) } else - @users = User.where(role: Role.get(params[:role])) + if role = Role.get(params[:role]) + @users = User.where(role: role) + else + flash[:alert] = "role '#{params[:role]}' does not exist!" + redirect_to users_path + return + end end else @users = User.where.not(id: User.first.id) #Remove first user diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 33fed1d..e445b8d 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,9 +1,11 @@ <% if params[:role] %> -

<%= title "All '#{params[:role]}' Users" %>

+

<%= title "All '#{params[:role]}' role users" %>

<%= link_to "show all", users_path %> <% else %>

<%= title "All Users" %>

<% end %> +

User count: <%= @users.length %>

+
<% @users.each do |u| %>