Ruby-on-rails – Active Record – Get the second, third.. item in a database (without ID)

activerecorddatabaseruby-on-railsruby-on-rails-3

How to I retrieve the second, third .. entries in a database. I don't want to use the auto incrementing id generated by rails.

As I am deleting entries from my database, so the ID continues to increase.

So my DB would have

id : 210 (Even thought it's currently the first value)
id : 211 (Even thought it's currently the second value)

I know "Phone.first" will return the first how do I get the second.

Sub Question-
Destroy_all/delete_all
only removes the item, Can I remove all entries from the DB and have the DB id's start from one without dropping the table. As I ran into problems.

Best Answer

Say you want the fourth user:

 @users = User.limit(4)
 @fourth_user = @users[3]

Concerning your second question, destroy_all should do the trick since it triggers all callbacks. Be sure to add :dependent => :destroy in your relationships.