From: Aldric Giacomoni Date: 2009-09-30T03:26:29+09:00 Subject: Re: Sequel accessor methods You -could- make your life a ton easier and set a class variable with the total count of created objects. Then you just refer to that variable and increment by one - bingo, new id. That's neither here nor there, though. "return parking_spot_number" and "start_point" do the same thing in Ruby. I don't understand how you're calling that function. Replace it with a dummy function like: def dummy return "It's alive!" end And check to see if Javascript properly gets "It's alive!" or not. 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? > > 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. -- Posted via http://www.ruby-forum.com/.