Forum: Ruby on Rails How to get recently saved record...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
32883bb85bebc818a1794e90e8c1ec81?d=identicon&s=25 mani (Guest)
on 2007-06-29 11:14
(Received via mailing list)
hi all..

im new to developin a app in which wen a record is created
through create method in controller create method in
controller is shown below...

chatusers---->table2 foreign key of table2 refers table1's primary

def create
    @chatuser =[:chatuser])

if Voicechat.find(@chatuser.voicechat_id).password ==


flash[:notice] = 'Sign in Successfull..'

 @chatuser_pages, @chatusers
=paginate(:chatusers, :conditions=>["voicechat_id=?",

redirect_to :action => 'list'
      render :action => 'new'
flash[:notice]='Plz enter correct password.'
render :action => 'new'


and here comes my list method..

def list

 @chatuser_pages, @chatusers
=paginate(:chatusers, :conditions=>["voicechat_id=?",


the problem is that @chatuser is local to create method... but i want
the foreign key of that that i can use it in list there a way to get the recently saved that i
can use that....plz anyone help me would be great even if u
provide alternate solution.....thanks in advance...
588ab1c0a5610a7e160a3b101abb91e6?d=identicon&s=25 Michael Latta (Guest)
on 2007-06-29 17:28
(Received via mailing list)
The create method I assume is from a user request, so it is a
different HTTP request from the list.  The data from the create
method is long gone, and could even be in a different mongrel server.

If you want to highlight the last created record you will need to
store in each record the creation time and the creating user, then
compare those to the current user and highlight the newest record in
the list.  There are standard column names for time stamps that will
be set by AR when a record is saved, but setting the user will need
to be done in a before_save filter or in your app logic.

This topic is locked and can not be replied to.