From: John W Higgins Date: 2009-09-30T03:20:42+09:00 Subject: Re: Sequel accessor methods --00c09f972055b485440474bb78fe Content-Type: text/plain; charset=ISO-8859-1 Jake, On Tue, Sep 29, 2009 at 11:12 AM, Jake Brightmatter wrote: > > def find_unused_house_id(start_point = 0) > > while (DataBase[:house][:id => start_point]) > > start_point += 1 > > end > > start_point > > end > > This is what I had written when you came alone. > > def find_unused_house_id() > parking_spot_number = 0 > while(DataBase[:house][:id => parking_spot_number]) > parking_spot_number += 1 > end > return parking_spot_number > end > > eerie right?! You were right on the money of what I wanted. I had > assumed that a 'nil' return would be taken as false. By your code > example, i was correct to assume that. I also was explicitly returning > the value, why didn't you? Is that a ruby thing? > Yes, ruby will implicitly return the last value in a function so the "start_point" line from my code acts exactly like your return parking_spot_number line. > > My only issue is that this does not work and I don't know why. I have > essentially what you have right? It should be noted that I am calling > this function in an odd way. I am using JavaScript from a *.rhtml file > using a direct 'request' via this code: > > var myHouseRequest = new Request({ > url: "/find_unused_house_id/" > }).send(); > > now I explicitly returned the count from ruby but I have no access to > the variable 'parking_spot_number' from the JavaScript. At least I > don't think I do. > > So although I think the ruby code should work, I have no proof that it > is working. > You should probably just mock up something that can call into the function directly without any javascript or any other layers and ensure first that you are getting back the appropriate value from your function. Then work on getting the call to work from javascript. John --00c09f972055b485440474bb78fe--