Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a slightly less cluttered solution that should do what you need, though it also assumes that you get rid of the <code>:appointment_date</code> field and change <code>:appointment_time</code> to a <code>DateTime</code> field. For more info on <strong>DateTimes</strong> check out:</p> <p>(Stackoverflow will only allow me to post 2 links because I'm a n00b so search "DateTime Ruby" on your favorite search engine for documentation for the Ruby and rails methods for DateTime)</p> <p>Formatting DateTime to string for views: <a href="http://apidock.com/ruby/DateTime/strftime" rel="nofollow">http://apidock.com/ruby/DateTime/strftime</a></p> <p>Intro on using DateTimes in forms: <a href="http://guides.rubyonrails.org/form_helpers.html#using-date-and-time-form-helpers" rel="nofollow">http://guides.rubyonrails.org/form_helpers.html#using-date-and-time-form-helpers</a></p> <pre><code>@appointment = Appointment.new(params[:appointment]) set_variables if @appointment.save if @procedure.occurence == "WEEKLY" multiplier = 7 elsif @procedure.occurence == "BIWEEKLY" multplier = 14 else multiplier = 30 end @visits = @procedure.visits - 1 @visits.times do |n| Appointment.create!( :procedure_id =&gt; @appointment.procedure_id, :patient_id =&gt; @appointment.patient_id, :appointment_time =&gt; (@appointment.appointment_time + (multiplier * n).days), :attendance =&gt; "SCHEDULED" ) end else flash.now[:error] = "There appears to be an error, please try again." render 'new' end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload