I want to have the users index page to list the admin and normal users separately, the below where you can select the Student or Admin view, via what I’d presume would be links…
Index view for users…
<h1>Listing users</h1>
<p><b><u>Students</u></b> <u>Admins</u></p>
<table>
<tr>
<th>Email</th>
<th>Login count</th>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= user.email %></td>
<td><%= user.login_count %></td>
</tr>
<% end %>
</table>
<p><%= link_to 'New User', new_admin_user_path %></p>
In my Users controller
class Admin::UsersController < ApplicationController
before_filter :require_admin_user
def index
# @users = User.admin
@users = User.students.paginate page: params[:page], order: 'created_at desc', per_page: 20
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @users }
end
end
Is this possible?
If you’re set on having two different tables for the two then doing another view would be the easiest way. The top links could be just how you want them.
Is there a reason you’re set against having a table combining all users and then a column to differentiate if they’re an admin? That would make it a lot easier to do what you’re looking for.