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.
Ishara G. (Guest)
on 2008-10-30 14:06
(Received via mailing list)
can anyone tell me how can i get the last id(primary key) of the table
MaD (Guest)
on 2008-10-30 14: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 G." <removed_email_address@domain.invalid>
MaD (Guest)
on 2008-10-30 14:11
(Received via mailing list)
oh forgot to ask for id:
YourObjectName.last.id
Naga harish K. (Guest)
on 2008-10-30 14: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 G. wrote:
> can anyone tell me how can i get the last id(primary key) of the table
Ishara G. (Guest)
on 2008-10-30 14:28
(Received via mailing list)
thanx,i did it,it was success

2008/10/30 Naga harish Kanegolla <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.