Getting the ID of a newly saved record

Quick question:

How do I get the ID of a newly saved record right after its been saved
with the .save method?

For example: @message.save

@message.id is blank. I’m sure this is an easy answer, thanks in
advance.

Hey,

the easy answer is: did the save() fail because of validation errors?

Trevor

You could use @message.to_param

[email protected] wrote:

Quick question:

How do I get the ID of a newly saved record right after its been saved
with the .save method?

For example: @message.save

@message.id is blank. I’m sure this is an easy answer, thanks in
advance.

You may want to just double check that the ID field on your table is
called “id” and not something else, and that it is set to
auto-increment.

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