Skip to content

Instantly share code, notes, and snippets.

@jmercedes
Last active December 11, 2015 12:38
Show Gist options
  • Save jmercedes/4601645 to your computer and use it in GitHub Desktop.
Save jmercedes/4601645 to your computer and use it in GitHub Desktop.
<h1><%= @doctor.name %></h1>
<%= simple_form_for([@doctor, @appointment], :html => { :multipart => true, :class => 'form-horizontal' }) do |f| %>
<%= f.error_notification %>
<%= f.input :full_name %>
<%= f.input :email %>
<%= f.input :adate, as: :date_picker %>
<%= f.input :atime, as: :time_picker %>
<%= f.input :personal_id %>
<%= f.input :insurance_id %>
<%= f.input :prescription %>
<div class="controls"><%= f.button :submit, class: "btn btn-primary" %></div>
<% end %>
class Appointment < ActiveRecord::Base
attr_accessible :adate, :atime, :doctor_id, :personal_id, :insurance_id, :prescription, :full_name, :email
validates :full_name, :presence => true
validates :email, :presence => true,
:format => {
:with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i,
:message => I18n.t('activerecord.errors.models.appointment.attributes.email.email_format')}
validates :adate, :presence => true
validates :atime, :presence => true
validates :adate, :uniqueness => { :scope => :atime, :message => "This date is not available" }
belongs_to :doctor
validates_date :adate, :after => lambda { Date.current }
mount_uploader :personal_id, FileUploader
mount_uploader :insurance_id, FileUploader
mount_uploader :prescription, FileUploader
validate :adate, :doctor_availability
def doctor_availability
if !adate.sunday? && !schedule.sun?
errors.add(:adate, "The doctor is not available on this date")
end
end
NameError in AppointmentsController#create
undefined local variable or method `schedule' for #<Appointment:0x007fa0dd3d0ab0>
app/models/appointment.rb:29:in `doctor_availability'
app/controllers/appointments_controller.rb:42:in `create'
class Schedule < ActiveRecord::Base
attr_accessible :doctor_id, :sun, :mon, :tue, :wed, :thu, :fri, :sat
belongs_to :doctor
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment