我開始通過一個小項目使用Rails。所有主要事情都在一些醫生,患者和諮詢之間。 我正在學習一本書來開始我的應用程序,現在,它運行良好,但我仍然需要小小的幫助!
例如,一旦創建了醫生,我可以創建一個諮詢,但是我的諮詢需要一個患者,而且我不知道如何在創建諮詢時呈現患者列表。
有人有線索嗎?
PS:這是我的代碼
=> DOCTOR
require 'digest'
class Doctor < ActiveRecord::Base
attr_accessible :birthdate, :birthplace, :city, :country, :firstname, :id_card_no, :lastname, :mail, :password, :secu_no, :street, :street_number, :zip
attr_accessor :password
validates :birthdate, :birthplace, :city, :country, :firstname, :lastname, :id_card_no, :secu_no, :street, :street_number, :zip, :presence=>true
validates :id_card_no,:secu_no, :uniqueness=>true
validates :street_number, :zip, :numericality=>true
validates :password, :confirmation => true,
:length => { :within => 4..20 },
:presence => true,
:if => :password_required?
validates :mail, :uniqueness => true,
:length => { :within => 5..50 },
:format => { :with => /^[^@][\w.-][email protected][\w.-]+[.][a-z]{2,4}$/i }
has_and_belongs_to_many :offices
has_and_belongs_to_many :specialities
has_and_belongs_to_many :secretaries
has_many :consultations
default_scope order('doctors.lastname')
before_save :encrypt_new_password
def self.authenticate(email, password)
user = find_by_email(email)
return user if user && user.authenticated?(password)
end
def authenticated?(password)
self.hashed_password == encrypt(password)
end
protected
def encrypt_new_password
return if password.blank?
self.hashed_password = encrypt(password)
end
def password_required?
hashed_password.blank? || password.present?
end
def encrypt(string)
Digest::SHA1.hexdigest(string)
end
end
=>病人
class Patient < ActiveRecord::Base
attr_accessible :birthdate, :birthplace, :city, :country, :firstname, :id_card_no, :job, :lastname, :secu_no, :street, :street_number, :zip
validates :birthdate, :birthplace, :city, :country, :firstname, :lastname, :id_card_no, :secu_no, :street, :street_number, :zip, :presence=>true
validates :id_card_no,:secu_no, :uniqueness=>true
validates :street_number, :zip, :numericality=>true
has_many :consultations
default_scope order('patients.lastname')
end
=>諮詢
class Consultation < ActiveRecord::Base
attr_accessible :date, :hour
validates :date, :hour, :presence=>true
belongs_to :patient
belongs_to :doctor
has_one :patient_description
has_one :consultation_file
has_and_belongs_to_many :illnesses
has_and_belongs_to_many :symptoms
end
謝謝!
托馬斯
是感謝,我發現了一些例子還有如果有人有相同的概率=> http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/collection_select – tomzi