How to get recently saved record

hi all…

im new to rails…im developin a app in which wen a record is created
through create method in controller class…my create method in
controller is shown below…

voicechats—>table1
chatusers---->table2 foreign key of table2 refers table1’s primary
key…

def create
@chatuser = Chatuser.new(params[:chatuser])

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

if @chatuser.save

flash[:notice] = ‘Sign in Successfull…’

@chatuser_pages, @chatusers
=paginate(:chatusers, :conditions=>[“voicechat_id=?”,
@chatuser.voicechat_id],:per_page=>18)

redirect_to :action => ‘list’
else
render :action => ‘new’
end
else
flash[:notice]=‘Plz enter correct password.’
render :action => ‘new’

end
end

and here comes my list method…

def list

@chatuser_pages, @chatusers
=paginate(:chatusers, :conditions=>[“voicechat_id=?”,
@chatuser.voicechat_id],:per_page=>18)

end

the problem is that @chatuser is local to create method… but i want
the foreign key of that record…so that i can use it in list
method…is there a way to get the recently saved record…so that i
can use that…plz anyone help me out…it would be great even if u
provide alternate solution…thanks in advance…

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.

Michael

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs