Wednesday, 28 August 2013

nested, recursive iterations RoR

nested, recursive iterations RoR

I have a big problem.
I'll try to clearly describe the situation!
I have a set of cars. Each car has a date on which it is available.
I have to fix an appointment day on which I'll be able to pick several
cars from my set, and this day must correspond to the day on which all of
the cars I picked are available, see the thing?
The relationships between my model: a one-to-many relationship between
availability and cars, a many-to-many relationship between appointment and
cars.
The idea I had was to pick up the first availability of the first car,
compare it to all availabilities of the second car if there's an equal do
the same with the third car availabilities, if not check the same with the
second availability of the first car etc. I think the idea could work, but
I'm having problems to put it into code. This is what I began with but
it's totally incomplete:
def add_car
@car = Car.find(params[:id])
@appointment = Appointment.find(params[:id])
@i = 0
@cars= []
@car.each do |d|
@cars << d
end
end

No comments:

Post a Comment