Topic: obtain model id from autocomplete / nested attributes
I want to add multiple persons to a meeting using an AJAX auto-complete textfield.
Typing in the textfield searches the list of existing users, pressing a button adds
the user to a list dynamically on the client.
The model is only stored when the submit button is pressed. If the person does not exists yet, he/she is created.
I have setup a many-to-many association between meetings and persons, which I handle with nested attributes in the meeting controller. I have an autocomplete textfield that searches the persons and a corresponding button.
I can dynamically insert a nested form per person into the DOM as input to the nested attributes in the meeting controller, but for this I need the id of the person, as well as the name.
My question is how I can obtain the persons name as well as the person_id from an autocomplete textfield. Optimally I would be able to retrieve other attributes such as lastname, too.
I could probably hack something, but I had hoped that there is a standard way of doing this.
Any hints what I could look for?