Hi
I’m not too sure how best to explain this but here goes!
I am trying to write an appointment system. I have, through example,
just about got the dynamics correct. Even tried to play with some
table joins (and excuse me if I’ve used the incorrect terminlogy). But
no matter what I try I can’t seem to get the following code to work.
I have a cart filled with Treatment id’s. I have a LineItem model set
up as follows:
class LineItem < ActiveRecord::Base
belongs_to :appointment
belongs_to :customer
belongs_to :therapist
belongs_to :treatment
end
I have worked out enough to be able to create a new LineItem record.
I have populated it with appointment, customer and therapist data. But
I cannot seem to get the treatment information from the cart into the
LineItem record.
Any ideas?
My code is as follows. I keep coming across this idea of using << but
none of the literature I’m reading makes a huge deal of sense.
@cart = find_treat
l = LineItem.new
c = Customer.find(session[:currentcustID])
t = Therapist.find(params[:appt_therapist])
a = Appointment.new
a.appdate = params[:appt_date]
a.apptime = params[:appt_time]
a.applength = @cart.total_time
a.customer = c
l.appointment = a
l.customer = c
l.therapist = t
tr = Treatment.new
@cart.items.each do |item|
tr = Treatment.find(item.id)
logger.warn("Currently Dealing with: #{tr.desclong}")
l.treatment << tr
end
#l.save
I keep getting variations of the following error message:
NoMethodError (You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<):
Thanks in advance for any help you might be able to give.
Darren