Q:

How to use = render @users, when _user.html partial is in different controller?

I have following code in AdminUsers controller
class AdminUsersController < ApplicationController
  def index
    @users = User.where(role: 'admin')
  end
end

And my index.html.haml looks like this
%table
  %thead
    %tr
      %th Name
      %th Age
      %th role
  %tbody
    = render @users

Now Rails is trying to find _user.html.haml partial inside UsersController, but my partial is inside AdminUsersController. Is there any way I can tell Rails to looks for partial inside AdminUsersController ?
I can solve the error by moving my partial under UsersController or by writing loop like this:
 - @users.each do |user|
    %tr
      // code

But it will be nice if I can use rails shorthand = render @users

A:

You need to specify the custom partial path and pass the @users collection to it. Your code should look like:
= render partial: "admin_users/user", collection: @users

Read details on Rendering Collections

