Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在RubyonRails中呈现子类列表?_Ruby On Rails_Ruby_Web_Rubygems - Fatal编程技术网

Ruby on rails 如何在RubyonRails中呈现子类列表?

Ruby on rails 如何在RubyonRails中呈现子类列表?,ruby-on-rails,ruby,web,rubygems,Ruby On Rails,Ruby,Web,Rubygems,你好 我开始通过一个小项目使用Rails。所有主要的事情都是在一些医生、病人和咨询之间进行的。 我正在学习一本书来开始我的应用程序,现在,它运行良好,但我仍然需要帮助的小曲折 例如,创建医生后,我可以创建咨询,但我的咨询需要患者,我不知道如何在创建咨询时呈现患者列表 有人有线索吗 这是我的密码 =>医生 require 'digest' class Doctor < ActiveRecord::Base attr_accessible :birthdate, :birthplace, :c

你好

我开始通过一个小项目使用Rails。所有主要的事情都是在一些医生、病人和咨询之间进行的。 我正在学习一本书来开始我的应用程序,现在,它运行良好,但我仍然需要帮助的小曲折

例如,创建医生后,我可以创建咨询,但我的咨询需要患者,我不知道如何在创建咨询时呈现患者列表

有人有线索吗

这是我的密码

=>医生

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
需要“摘要”
类医生true
验证:id\u卡号,:secu\u号,:唯一性=>true
验证:street_number,:zip,:numericality=>true
验证:密码,:确认=>true,
:length=>{:within=>4..20},
:presence=>true,
:if=>:需要密码吗?
验证:mail,:university=>true,
:length=>{:within=>5..50},
:format=>{:with=>/^[^@][\w.-]+@[\w.-]+[.][a-z]{2,4}$/i}
有很多办公室吗
有很多特产吗
你和你属于很多人吗:秘书
有很多:磋商
默认范围顺序('doctors.lastname')
保存前:加密新密码
def自我验证(电子邮件、密码)
用户=通过电子邮件查找(电子邮件)
如果用户&&user.authenticated?(密码),则返回用户
结束
def已验证?(密码)
self.hash_password==加密(密码)
结束
受保护的
def encrypt_新密码
如果password.blank返回?
self.hashed_password=加密(密码)
结束
是否需要def密码?
哈希密码。空白?||密码是多少?
结束
def加密(字符串)
摘要::SHA1.hexdigest(字符串)
结束
结束
=>患者

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 Patienttrue
验证:id\u卡号,:secu\u号,:唯一性=>true
验证:street_number,:zip,:numericality=>true
有很多:磋商
默认范围顺序('patients.lastname')
结束
=>咨询

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
课堂咨询true
属于:病人
属于:医生
有一个:病人描述
有一个:咨询文件
你和你属于许多疾病吗
有很多症状吗
结束
谢谢


Thomas

我认为您需要查看会诊“患者id”列上的“集合选择”。

我非常喜欢这样,因为它“了解”您的字段,例如,为关联或日期选择器自动创建选择框:

<%= semantic_form_for @consultation do |f| %>
  <%= f.inputs do %>
    <%= f.input :date %>
    <%= f.input :hour %>
    <%= f.input :doctor %>
    <%= f.input :patient %>
  <% end %>
  <%= f.actions do %>
    <%= f.action :submit, :as => :button %>
    <%= f.action :cancel, :as => :link %>
  <% end %>
<% end %>

:按钮%>
:link%>

然而,这不是一个纯粹的Rails解决方案,需要一个额外的Gem。我不确定这是否适合您的培训目的。

是的,谢谢,我发现了一些例子,如果有人有同样的问题=>