小编mik*_*182的帖子

Rails where 有多个条件

在我的应用程序中,我使用枚举定义了多个用户角色:

enum role: { staff: 0, clinician: 1, admin: 2 }
Run Code Online (Sandbox Code Playgroud)

员工用户每个都属于一所大学:

员工关注:

require 'active_support/concern'

module StaffUser
  extend ActiveSupport::Concern

  included do
    belongs_to :university
    has_many :patients
    has_many :referral_requests
    validates :university_id, presence: true, if: :staff?
  end
Run Code Online (Sandbox Code Playgroud)

大学模式

class University < ApplicationRecord
  has_many :staffs, -> { where role: :staff}, class_name: "User"
  has_many :clinicians, through: :lists
  has_many :whitelists
  belongs_to :market

  validates :market_id, presence: true
end
Run Code Online (Sandbox Code Playgroud)

我在患者/新视图上有一个 Staff Doctor 的下拉选择菜单,我想在其中显示与当前用户属于同一所大学的员工用户列表,但我似乎无法让它工作。目前,下拉菜单仅包含提示文本。我究竟做错了什么?

患者/新观点:

<%= form_for(@patient) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="checkbox">

    <h1>Tell …
Run Code Online (Sandbox Code Playgroud)

activerecord ruby-on-rails where

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

activerecord ×1

ruby-on-rails ×1

where ×1