I have modified a basic function for creating a new record.
def create
@contact = Contact.new(params[:contact])
@contact.user_id = current_user.id
@contact.save
end
I also have another table that holds records as to which users can
access which contacts. Essentially, it creates a row that has the
user_id and contact_id.
Since the id for the contact is automatically assigned as a primary key,
is there any way I can access it directly after the contact is saved -
or do I have to do a find to try to track down the record that was just
created?
On Jul 9, 2007, at 1:46 PM, Robert S. wrote:
access which contacts. Essentially, it creates a row that has the
user_id and contact_id.
Since the id for the contact is automatically assigned as a primary
key,
is there any way I can access it directly after the contact is saved -
or do I have to do a find to try to track down the record that was
just
created?
This was just discussed on the list: After the .save, @contact.id is
the primary key of the newly saved record.
However, did you know that you can do:
@contact = current_user.create_contact(params[:contact])
See the rdoc for belongs_to
-Rob
Rob B. http://agileconsultingllc.com
[email protected]