Friday, May 21, 2010

Delete old records from database if the number of records reached to max length

I need to maintain fixed number of records. While my method is going to insert a new record then the old record will be delete automatically if the number of records reached to max length.

Max_length = 4
def create
@students = Student.new(params[:student])
if @students.save
if Student.find(:all).length >= Max_length
@old_students = Student.first
@old_students.destroy
end
end
end

No comments:

Post a Comment