Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.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 数据库检查中的Ruby日期和时间_Ruby On Rails_Ruby_Forms - Fatal编程技术网

Ruby on rails 数据库检查中的Ruby日期和时间

Ruby on rails 数据库检查中的Ruby日期和时间,ruby-on-rails,ruby,forms,Ruby On Rails,Ruby,Forms,我是Ruby新手。我有创建新预约的表格(我保存在那里,医生id,患者id,日期,时间)我在数据库中也有时间表(医生id在时间表中是FK,有星期几,开始时间,结束时间)现在我想检查一下医生是否在选定的日期和时间有空,是否在这个日期和时间没有预约。如果我不能添加错误消息 翻译以便更好地理解: -dzien_tygodnia - day_of_the_week; -data_wizyty - visit_date; -godzina_wizyty - visit_time; -poczatek_pra

我是Ruby新手。我有创建新预约的表格(我保存在那里,
医生id
患者id
日期
时间
)我在数据库中也有时间表(
医生id
在时间表中是
FK
,有
星期几
开始时间
结束时间
)现在我想检查一下医生是否在选定的日期和时间有空,是否在这个日期和时间没有预约。如果我不能添加错误消息

翻译以便更好地理解:

-dzien_tygodnia - day_of_the_week;
-data_wizyty - visit_date;
-godzina_wizyty - visit_time;
-poczatek_pracy - start_working;
-koniec_pracy - end_working.
My
\u form.html.erb

    <%= form_for(@appointment) do |f| %>
  <% if @appointment.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@appointment.errors.count, "error") %> prohibited this appointment from being saved:</h2>

      <ul>
      <% @appointment.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :data_wizyty %><br />
  <%=
    options = { start_year: 2.year.from_now.year,
                end_year: 2013,
                include_blank: true,
                default: nil }
    f.date_select :data_wizyty, options
  %>
  <!--<input type="text" data-behaviour='datepicker' :data_wizyty > -->
  </div>
  <div class="field">
    <%= f.label :godzina_wizyty %><br />
    <%= f.time_select :godzina_wizyty %>
  </div>
  <div class="field">
    <%= f.hidden_field :doctor_id, :value => Doctor.find(session[:current_doctor_id2]).id %>
  </div>
  <div class="field">
    <%= f.hidden_field :patient_id, :value => Patient.find(session[:current_patient_id]).id %>
  </div>
  <div class="actions">
    <%= submit_tag "Utworz wizyte" %>
  </div>
<% end %>
class Appointment < ActiveRecord::Base
  validates :doctor_id, uniqueness: { scope: [:data_wizyty, :godzina_wizyty], message: 'Ten termin jest juz zajety!' }
  validate :doctor_is_scheduled

  attr_accessible :data_wizyty, :doctor_id, :godzina_wizyty, :notatka, :objawy_choroby, :patient_id



    belongs_to :patient
    belongs_to :doctor
    belongs_to :schedule
    belongs_to :refferal

    has_many :employees

  def doctor_is_scheduled
    if Schedule.where(doctor: doctor, dzien_tygodnia: data_wizyty.wday)
               .where('poczatek_pracy < ? and koniec_pracy > ?', godzina_wizyty, godzina_wizyty).empty?
      self.errors.add(:doctor, message: 'nie pracuje w tym terminie!')
    end
  end


end

你能告诉我应该包括哪些文件吗?

你在这里要找的是。阅读一下Rails指南,因为它将对您非常有帮助。关于您的问题,您应该能够使用以下内容:

class Appointment < ActiveRecord::Base
  validates :doctor_id, uniqueness: { scope: [:date, :time], 'already has an appointment at that time' }
  validate :doctor_is_scheduled

  def doctor_is_scheduled
    if Schedule.where(doctor: doctor, dayofweek: date.wday)
               .where('starttime < ? and endtime > ?', time, time).empty?
      self.errors.add(:doctor, 'is not scheduled to be working at that time')
    end
  end
end
班级预约?',时间,时间)。是否为空?
self.errors.add(:doctor,'未计划在该时间工作')
结束
结束
结束

第一行(
验证:医生id,唯一性:
)检查给定日期和时间的医生是否唯一,即不会重复预订医生。
doctor\u已安排
方法检查给定的医生和一周中的某一天,医生有一个班次(在
starttime
endtime
之间)安排。

您在这里寻找的是。阅读一下Rails指南,因为它将对您非常有帮助。关于您的问题,您应该能够使用以下内容:

class Appointment < ActiveRecord::Base
  validates :doctor_id, uniqueness: { scope: [:date, :time], 'already has an appointment at that time' }
  validate :doctor_is_scheduled

  def doctor_is_scheduled
    if Schedule.where(doctor: doctor, dayofweek: date.wday)
               .where('starttime < ? and endtime > ?', time, time).empty?
      self.errors.add(:doctor, 'is not scheduled to be working at that time')
    end
  end
end
班级预约?',时间,时间)。是否为空?
self.errors.add(:doctor,'未计划在该时间工作')
结束
结束
结束

第一行(
验证:医生id,唯一性:
)检查给定日期和时间的医生是否唯一,即不会重复预订医生。
doctor\u已安排
方法检查给定的医生和一周中的某一天,医生有一个班次(在
starttime
endtime
之间)安排。

您在这里寻找的是。阅读一下Rails指南,因为它将对您非常有帮助。关于您的问题,您应该能够使用以下内容:

class Appointment < ActiveRecord::Base
  validates :doctor_id, uniqueness: { scope: [:date, :time], 'already has an appointment at that time' }
  validate :doctor_is_scheduled

  def doctor_is_scheduled
    if Schedule.where(doctor: doctor, dayofweek: date.wday)
               .where('starttime < ? and endtime > ?', time, time).empty?
      self.errors.add(:doctor, 'is not scheduled to be working at that time')
    end
  end
end
班级预约?',时间,时间)。是否为空?
self.errors.add(:doctor,'未计划在该时间工作')
结束
结束
结束

第一行(
验证:医生id,唯一性:
)检查给定日期和时间的医生是否唯一,即不会重复预订医生。
doctor\u已安排
方法检查给定的医生和一周中的某一天,医生有一个班次(在
starttime
endtime
之间)安排。

您在这里寻找的是。阅读一下Rails指南,因为它将对您非常有帮助。关于您的问题,您应该能够使用以下内容:

class Appointment < ActiveRecord::Base
  validates :doctor_id, uniqueness: { scope: [:date, :time], 'already has an appointment at that time' }
  validate :doctor_is_scheduled

  def doctor_is_scheduled
    if Schedule.where(doctor: doctor, dayofweek: date.wday)
               .where('starttime < ? and endtime > ?', time, time).empty?
      self.errors.add(:doctor, 'is not scheduled to be working at that time')
    end
  end
end
班级预约?',时间,时间)。是否为空?
self.errors.add(:doctor,'未计划在该时间工作')
结束
结束
结束


第一行(
验证:医生id,唯一性:
)检查给定日期和时间的医生是否唯一,即不会重复预订医生。
doctor\u被安排
方法检查给定的医生和一周中的某一天,医生有一个班次(在
starttime
endtime
之间)安排。

当检查在该日期和时间没有预约时,这是否是与当前医生的预约,或者与任何医生预约?也就是说,多个医生可以同时预约吗?是的,他们可以,我只需要加上他们的工作时间:)好的,很好。在这种情况下,我相信我的解决方案应该对你有用。但我在这方面真的非常新,我认为这对我来说太难了:(当检查在该日期和时间没有预约时,这是与当前医生的预约,还是与任何医生的预约?即,多个医生可以同时预约吗?是的,他们可以,我只需添加他们工作的天数和时间:)好的,太好了。在这种情况下,我相信我的解决方案应该适合你。但我在这方面真的非常新,我认为这对我来说太难了:(当检查在该日期和时间没有预约时,这是与当前医生的预约,还是与任何医生的预约?即,多个医生可以同时预约吗?是的,他们可以,我只需添加他们工作的天数和时间:)好的,太好了。那样的话,我相信我的解决方案应该对你有用。但我真的,真的很新,我想这对我来说太难了