Let me clarify my question. I'm trying to get an integer value from @student.rooms.last, and it doesn't seem that @student.rooms.last alone will give me an integer value.
Student.transaction do
if @student.test!
x = @student.site_id.to_int
y = @student.rooms.last
book = Book.find(:first, :conditions => ["location_id = ? AND room_id = ?", x, y])
room = Room.new
room.student_id = @student.id
if room.save
book.room_id = room.id
Right now this returns an error: You have a nil object when you didn't expect it! The error occurred while evaluating nil.room_id= I'm trying to find the room record associated with @student that has an id equal to the book room_id foreign key. Thanks for any response.
@student.roomsjust to get the last element? I mean, why can't you just get the last element directly?firstorlastfrom a list if you don't tell Rails how you want the items ordered?