- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
创建预约时,假设组织“ABC”,我还可以看到属于其他组织的医生。它假设只列出来自“ABC”的医生,而不是其他人。我该怎么办。
谢谢。
我的预约表:
<%= simple_form_for(@appointment, :html => { :class => 'form-horizontal' }) do |f| %>
<div class="form-inputs">
<%= f.hidden_field :patient_id %>
<%= f.association :physician, :label_method => :first_name, :include_blank => false, :as => :radio_buttons, :required => true %>
<%= f.hidden_field :appointment_date, :value => DateTime.now %>
<%= f.hidden_field :organization_id, :value => current_user.organization_id%>
</div>
<div class="form-actions">
<%= f.button :submit, "Create Appointment" %>
</div>
<% end %>
我的模型:
/app/models/physician.rb
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
belongs_to :organization
attr_accessible :physician_name, :organization_id
end
/app/models/appointment.rb
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
belongs_to :organization
attr_accessible :physician_id, :patient_id, :appointment_date, :state, :organization_id
end
/app/models/patient.rb
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, :through => :appointments
belongs_to :organization
attr_accessible :patient_name, :organization_id
end
我的 Controller :
/app/controllers/appointment_controller.rb
class AppointmentsController < ApplicationController
def new
@appointment = Appointment.new
@appointment.patient_id = params[:patient_id]
end
def create
@appointment = Appointment.new(params[:appointment])
if @appointment.save
flash[:notice] = "New appointment record created"
redirect_to dashboards_path
else
render 'new'
end
end
end
最佳答案
这是因为 simple_form 不知道您的作用域。如果你告诉它:
<%= f.association :phyisician %>
它将简单地列出数据库中所有可用的医生。
解决方案是给它你想要显示的医生的集合,例如你可以写:
<%= f.association :physician,
:collection => @appointment.patient.organization.physicians,
:label_method => :first_name,
:include_blank => false,
:as => :radio_buttons,
:required => true %>
关于ruby-on-rails - 如何过滤或限定表格中的医生以仅列出属于组织的医生?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11916137/
如果有一张有客户的 table 和一张有地址的 table 。 一位客户必须(仅)有一个地址,但地址不必有客户(取决于字段类型)。所以我只是问如何告诉cake在寻找客户时获取客户地址,但在寻找地址时不
我有一个问题,我需要获取我的画廊表的所有图像(路径),该表拥有博物馆和拥有博物馆的用户。我得到了图像的路径,但这些与拥有博物馆的 user_id 没有关联。 所以简短的描述: 每个用户拥有一个博物馆,
我有一个问题,我需要获取我的画廊表的所有图像(路径),该表拥有博物馆和拥有博物馆的用户。我得到了图像的路径,但这些与拥有博物馆的 user_id 没有关联。 所以简短的描述: 每个用户拥有一个博物馆,
我有用户和个人资料(一对一属于用户) type User struct { ID int Username string Password string
我想以类似于'belongs to' association的方式使用GORM的Django's one-to-one relationships。考虑以下示例,其中每个User与一个Profile相
长期从事 Rails 开发, Backbone 菜鸟。 在我的 Rails 模型中,一个项目有很多任务,一个任务属于一个项目......标准的东西。 尝试在集合中获取项目的任务 json。 Examp
让我们直奔问题(使用 Grails 1.1.1,它应该适用于以前的问题) 我有 2 个域,即:用户和详细信息,如下所示: Class User { String userName ; ..
我正在尝试在 Rails 中设置模型关系,并且需要您的帮助,因为它不起作用:0 class User :creator_id end 就架构而言,request_threads表具有creator_
注意:我在编写问题时解决了问题,因此不需要答案。仍然与答案分享,以便有相同经历的人可以从中受益。 我有一个回收器 View ,其中包含图像和 2 个 TextView 。我想在单击图像时旋转图像,但发
我正在尝试为我的应用程序中的所有按钮添加自定义点击声音。我已经为 UIButton 创建了一个类类别,其中包含以下代码: NSURL *soundURL = [NSURL fileURLWithPat
我有这样一个IP:12.12.12.12 我正在遍历不同的 IP 范围(12.12.12.0/24(示例))格式,并尝试查看 IP 是否在该范围内。 我尝试了各种方法,例如 inet_addr 和比较
看完这个问题 ASP.NET MVC: Nesting ViewModels within each other, antipattern or no? 和 Derick Bailey 的评论 i t
我正在使用 FeedWordPress 从子公司网页将新闻导入母公司的新闻卷。 可在此处查看特定项目的 RSS 摘录:Pastebin 如您所见,我正在将我需要的图像放入 RSS 文件、描述 bloc
假设我有以下数据库架构: dogs 和 owners 与经典的 belongsToMany 相关联。 walks 表怎么样?我希望能够在这种关系中使用 Eloquent 好东西: $dogs = Do
我不知道出了什么问题,但我无法使用 :class_name 选项让belongs_to 工作。有人可以启发我。非常感谢! 这是我的代码片段。 class CreateUsers false
属于 JavaScript 对象原型(prototype)的回调函数如何访问对象成员?回调不能关闭,一切都必须定义如下: function Obji(param){ this.element =
有人可以解释一下 MarkupCompilePass1 和 PartialClassGenerationTask 这两个构建任务是如何归属在一起的吗?目前我不知道他们是否共存或者是否需要对方。有人可以
现在,我尝试了解 Grails 域类和 GORM 中的工作原理。所以,我尝试实验: 我试验了两个域类:Main 和 Sub。 我们走吧! 第 1 步: class Main { String
所以我有一个模型 App.DailyEntry = DS.Model.extend({ user_id: belongsTo('user'), entries: hasMany('En
我正在使用 primeng 组件选项卡菜单。 https://www.primefaces.org/primeng/#/tabmenu我找不到将所选 TAB 的颜色更改为不同颜色的方法。 最佳答案 抱
我是一名优秀的程序员,十分优秀!