How to get id of the saved record in Ruby on Rails

Posted by railsnew on Stack Overflow See other posts from Stack Overflow or by railsnew
Published on 2010-04-25T21:00:46Z Indexed on 2010/04/28 20:47 UTC
Read the original article Hit count: 195

Filed under:
|

I am doing this from the console but I'd like to do this in my code too. Basically I am trying to add a record to the table and then get the id back.

>> @record = Physician.create(:pname => "someone2")
=> #<Physician id: nil, pname: "someone2", pgroup: nil, created_at: nil, updated_at: nil, userid: nil, storeid: nil, licexpdate: nil, address: nil>
>> @record.save
=> false
>>

© Stack Overflow or respective owner

Related posts about rails

Related posts about activerecord