2
我想弄清楚我怎么能有我的预约形式作为radio_buttons的医生名单。现在,如果我使用“f.input:physician_id,:as =>:radio_buttons”,我会得到一个“是/否”单选按钮。如果我更改为“f.association:physician_id,:as =>:radio_buttons”,那么我得到RuntimeError“Association:user_id not found”。单选按钮上使用simple_form has_many通过关联belongs_to侧特别是关联
顺便说一下,我使用simple_form这个。
谢谢。
我的约会形式:
<%= 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 %>
我的模型:
/app/models/physician.rb
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
attr_accessible :physician_name
end
/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
我的控制器:
/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
尝试'f.association:医师,:as =>:radio_buttons' – 2012-08-09 11:44:44
这是有效的。谢谢 :-) – Azren 2012-08-09 13:39:22