Hi, I''m having trouble with one of my apps. I''m trying to make a studio booking software. Before creating a booking, I want to check if the studio is available. I have a method checking for the availability of the studio which returns false if the studio is already booked. The problem is that the method returns ''nil'' if the checking process succeeds. I tried a bunch of methods but none of them worked :( here is my code : def check_dispo(date, time, time_duration, week_duration) i = 0 end_time = time + time_duration.strftime(''%H'').to_i*3600 + time_duration.strftime(''%M'').to_i*60 while i < week_duration studio_bookings = StudioBooking.find(:all, :conditions => ["start_date = ?", date]) for studio_booking in studio_bookings studio_booking_end_time = studio_booking.time + studio_booking.time_duration.strftime(''%H'').to_i*3600 + studio_booking.time_duration.strftime(''%M'').to_i*60 unless time >= studio_booking_end_time || end_time <studio_booking.time return false end end i += 1 date = date + 7 end return true end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi I wrote this method to check for the availability of a studio : def check_dispo(date, time, time_duration, week_duration) i = 0 end_time = time + time_duration.strftime(''%H'').to_i*3600 + time_duration.strftime(''%M'').to_i*60 while i < week_duration studio_bookings = StudioBooking.find(:all, :conditions => ["start_date = ?", date]) for studio_booking in studio_bookings studio_booking_end_time = studio_booking.time + studio_booking.time_duration.strftime(''%H'').to_i*3600 + studio_booking.time_duration.strftime(''%M'').to_i*60 unless time >= studio_booking_end_time || end_time <studio_booking.time return false end end i += 1 date = date + 7 end return true end it returns false in case it''s booked but returns ''nil'' instead of true otherwise :( HELP PLEASE !!! Pat --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 09/05/2007, at 5:46 AM, Pat wrote:> The problem is that the method returns ''nil'' if the checking process > succeeds.Well, your method has two return statements in it, neither of which return nil, so this sounds impossible to me. Can you give an example set of arguments for which your method will return nil? Pete Yandell http://notahat.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---