予定フォームにradio_buttonsとして医師のリストを含めるにはどうすればよいかを理解しようとしています。ここで、「f.input:physician_id、:as =>:radio_buttons」を使用すると、「はい/いいえ」のラジオボタンが表示されます。また、「f.association:physician_id、:as =>:radio_buttons」に変更すると、RuntimeError「Association:user_idnotfound」が発生します。
ちなみに、これには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