Ruby on rails 使用简单表单的单选按钮在关联的“属于”侧具有多个直通关联
我想知道如何在我的预约表中把医生列表作为单选按钮。现在如果我使用“f.input:medicine\u id,:as=>:单选按钮”,我会得到一个“Yes/No”单选按钮。如果我改为“f.association:medicine\u id,:as=>:radio\u buttons”,那么我将得到运行时错误“association:user\u id not found” 顺便说一下,我用的是简单的表格 谢谢 我的预约表格:Ruby on rails 使用简单表单的单选按钮在关联的“属于”侧具有多个直通关联,ruby-on-rails,simple-form,Ruby On Rails,Simple Form,我想知道如何在我的预约表中把医生列表作为单选按钮。现在如果我使用“f.input:medicine\u id,:as=>:单选按钮”,我会得到一个“Yes/No”单选按钮。如果我改为“f.association:medicine\u id,:as=>:radio\u buttons”,那么我将得到运行时错误“association:user\u id not found” 顺便说一下,我用的是简单的表格 谢谢 我的预约表格: <%= simple_form_for(@appointment
<%= simple_form_for(@appointment) do |f| %>
<div class="form-inputs">
<%= f.hidden_field :patient_id %>
<%= f.input :physician_id, :as => :radio_buttons %>
<%= f.hidden_field :appointment_date, :value => DateTime.now %>
</div>
<div class="form-actions">
<%= f.button :submit, "Create Appointment" %>
</div>
<% end %>
:单选按钮%>
DateTime.now%>
我的模型:
/app/models/medicine.rb
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
attr_accessible :physician_name
end
class医生:预约
属性可访问:医生姓名
结束
/app/models/appointment.rb
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
attr_accessible :physician_id, :patient_id, :appointment_date, :state
end
班级预约
/app/models/patient.rb
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, :through => :appointments
attr_accessible :patient_name
end
class Patient:预约
属性可访问:患者名称
结束
我的控制器:
/app/controllers/appointment\u 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
类指定控制器
您应该将关联名称传递给关联
方法
f.association :physician, :as => :radio_buttons
尝试
f.关联:医师,:as=>:单选按钮