3张桌子彼此互动,但患者ID归零

时间:2019-01-15 21:21:39

标签: ruby-on-rails ruby

所以我有三个相互关联的模型。我有病人,提供者和清单。患者可以有很多提供者,反之亦然。名单是中间人。患者可以将提供者添加到列表中,该列表可以完美运行,并在list_id上显示所有提供者。但是,在提供方方面,当我尝试向所有提供方提供患者时。我收到一条错误消息:“找不到具有“ id”的患者= enter image description here

SELECT brewery_name, ibu, avg_ibu
FROM (SELECT br.name as brewery_name, ibu,
             AVG(ibu) OVER (PARTITION BY b.brewery_id ORDER BY ibu DESC) as avg_ibu,
             COUNT(ibu) OVER (PARTITION BY b.brewery_id) as cnt_ibu
      FROM beers b JOIN
           breweries br
          ON b.brewery_id = br.brewery_id
      WHERE ibu IS NOT NULL
     ) bb
WHERE cnt_ibu >= 5;

<-这是我的Patient_access.html.erb文件->

class ProvidersController < ApplicationController
def patient_access
        @provider = current_user.provider
        @active_patients = @provider.lists.where(soft_delete: false)
        render "providers/patient_access"
    end
end

<!-- Here is the patients controller which everything works fine on the patients side of the app as far as displaying all providers that belongs to that patient -->

class PatientsController < ApplicationController
def provider_access
        flash[:modal] = true
        @patient = Patient.find(params[:patient_id])
        @active_providers = @patient.lists.where(soft_delete: false)

    end
end

1 个答案:

答案 0 :(得分:0)

在视图中,您有一个链接:<%= link_to patients_path(id: provider.id) %> 并且在控制器@patient = Patient.find_by_id(params[:id])中-实际上等于@patient = Patient.find_by_id(provider.id),当然,rails找不到这样的记录。

如果要查找特定的患者,则应将patient_id传递给该操作。