marston-8Qo2DTIsO68RmelmmXo44Q@public.gmane.org
2006-Nov-23 22:07 UTC
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey, the easy answer is: did the save() fail because of validation errors? Trevor On 23-Nov-06, at 2:07 PM, marston-8Qo2DTIsO68RmelmmXo44Q@public.gmane.org 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You could use @message.to_param marston-8Qo2DTIsO68RmelmmXo44Q@public.gmane.org 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.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---