【发布时间】:2013-06-20 20:41:04
【问题描述】:
你好,
我通过一个小项目开始使用 Rails。所有主要的事情都在一些医生、病人和咨询之间。 我正在学习一本书来开始我的应用程序,现在它运行良好,但我仍然需要帮助来解决一些小问题!
例如,一旦创建了医生,我可以创建咨询,但我的咨询需要患者,而我不明白如何在创建咨询时呈现患者列表。
有人知道吗?
PS:这是我的代码
=> 医生
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.-]+@[\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
谢谢!
托马斯
【问题讨论】:
标签: ruby-on-rails ruby web rubygems