Forum: Ruby on Rails retrieve previous id

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.
B5a793b425c4db1f45c3cdfec5697047?d=identicon&s=25 ss (Guest)
on 2006-05-09 12:14
Hi,

I have this piece of code,

if @quote.save
      flash[:notice] = 'Quote was successfully created.'

      #return id of preiously inserted quote

      #enter this id in the correct related project field

      redirect_to :action => 'list'

end

How can I return the id of the saved data?
5233478c51a92b6a1a5c970cbf3a42f3?d=identicon&s=25 Isak Hansen (Guest)
on 2006-05-09 13:32
(Received via mailing list)
On 5/9/06, ss <scott@boxuk.com> wrote:
>
> How can I return the id of the saved data?

@quote.id, or just @quote, should return a value once the record's been
saved.

-Isak
468f4fd55bf0dac4813dc92f07b42fca?d=identicon&s=25 Sergio Luis (malvadomx)
on 2006-05-09 19:25
ss wrote:
> Hi,
>
> I have this piece of code,
>
> if @quote.save
>       flash[:notice] = 'Quote was successfully created.'
>
>       #return id of preiously inserted quote
>
>       #enter this id in the correct related project field
>
>       redirect_to :action => 'list'
>
> end
>
> How can I return the id of the saved data?

yes, you can use @quote.id after being saved, before being saved you can
not use @quote.id
This topic is locked and can not be replied to.