Forum: Ruby on Rails get the id of the last record from a table

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dcf093a36c8a7e286dbefe10454813e1?d=identicon&s=25 Ishara Gunathilake (Guest)
on 2008-10-30 13:06
(Received via mailing list)
can anyone tell me how can i get the last id(primary key) of the table
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2008-10-30 13:09
(Received via mailing list)
i don't know if i understand correctly what you want to do, but you
could just type:
YourObjectName.last


On 30 Okt., 13:05, "Ishara Gunathilake" <jaimgunathil...@gmail.com>
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2008-10-30 13:11
(Received via mailing list)
oh forgot to ask for id:
YourObjectName.last.id
C4fee92c07e4fee216aeab5be40e6cc9?d=identicon&s=25 Naga harish Kanegolla (nagaharish)
on 2008-10-30 13:14
If you want only the id of the last entered data then try this,
 User.maximum('id')
This will return the maximum id which will be anyways the last one.

Ishara Gunathilake wrote:
> can anyone tell me how can i get the last id(primary key) of the table
Dcf093a36c8a7e286dbefe10454813e1?d=identicon&s=25 Ishara Gunathilake (Guest)
on 2008-10-30 13:28
(Received via mailing list)
thanx,i did it,it was success

2008/10/30 Naga harish Kanegolla <rails-mailing-list@andreas-s.net>
This topic is locked and can not be replied to.