title: Filter user by role on select rails
body: <p>I have user with role : admin, manager, cashier. User model relation with Employee model.</p>
  
  <p>Employee belongs_to User and
  User has_many Employee</p>
  
  <p>In new form employee, i used this method</p>
  
  <pre><code>&lt;%= form_for @employee, remote: true, html: {role: "form", multipart: true} do |f| %&gt;
    &lt;div class="form-group"&gt;
      &lt;%= f.label :user_id, 'User', class: "exampleInputEmail1" %&gt;
      &lt;%= f.select :user_id, options_for_select(@users.map {|u|[u.name, u.id]}, f.object.user_id), {prompt: "Select User"}, class: "form-control" %&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>Using a method above, i get all of user. But i want to filter only user with role "admin" on the select. How to get that?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>employees_controller</p>
  
  <p>new and create action</p>
  
  <pre><code>  def new
      @employee = Employee.new
      @users = User.all
    end
  
    def create
      @employee = Employee.new(employee_params)
      @users = User.all
      respond_to do |format|
        if @employee.save
          format.html { redirect_to employees_path, notice: 'Employee was successfully created.' }
          format.json { render :show, status: :created, location: @employee }
          format.js
        else
          format.html { render :new }
          format.json { render json: @employee.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Forget to add this. Relation user and role.</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :user_roles, :dependent =&gt; :destroy
    has_many :roles, :through =&gt; :user_roles
  end
  
  class Role &lt; ActiveRecord::Base
    has_many :user_roles, :dependent =&gt; :destroy
    has_many :users, :through =&gt; :user_roles
  end
  </code></pre>
  
  <p><strong>Edit 3</strong></p>
  
  <p>schema.rb</p>
  
  <pre><code>  create_table "roles", force: :cascade do |t|
      t.string   "name"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end
  
    add_index "roles", ["name"], name: "index_roles_on_name", unique: true, using: :btree
  
    create_table "user_roles", force: :cascade do |t|
      t.integer  "user_id"
      t.integer  "role_id"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end
  
    add_index "user_roles", ["role_id"], name: "index_user_roles_on_role_id", using: :btree
    add_index "user_roles", ["user_id"], name: "index_user_roles_on_user_id", using: :btree
  
    create_table "users", force: :cascade do |t|
      t.string   "name"
      t.string   "gender"
      t.string   "username"
      t.string   "email"
      t.string   "salt"
      t.string   "encrypted_password"
      t.string   "auth_token"
      t.string   "password_reset_token"
      t.datetime "password_reset_sent_at"
      t.datetime "created_at",             null: false
      t.datetime "updated_at",             null: false
    end
  
    add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
    add_index "users", ["username"], name: "index_users_on_username", unique: true, using: :btree
  
    add_foreign_key "user_roles", "roles"
    add_foreign_key "user_roles", "users"
  
    create_table "employees", force: :cascade do |t|
      t.string   "employee_code"
      t.string   "name"
      t.string   "age"
      t.string   "address"
      t.string   "telp"
      t.datetime "created_at",    null: false
      t.datetime "updated_at",    null: false
      t.integer  "user_id"   
    end
  </code></pre>