views:

145

answers:

2

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
>>
A: 

If @record.save returns false, the item wasn't saved and it doesn't have an ID. Use @record.errors.full_messages to see what went wrong

Gareth
A: 

When you successfully save your object, you can access its ID property and get what you need.

Francisco Soto