This is pretty simple, I just can’t quite get it. I’m sure there’s a rails-way to do it.
When creating a new comment, I want the user to be able to enter her name in a field, but have the form submit the matching ID for her name (or toss an error/create new person).
Thanks!
There are a couple of ways to go about this:
User.find_by_firstname_and_lastname(firstname, lastname). If none exists, tell the user to create one.Option 1 is very error prone, but option 2 requires quite a bit more work. Honestly, this is going to be a hard one to pull off properly. What do you do if there are two John Smiths? How do they know which one to choose, how do you choose in the backend, etc.
I would highly suggest making it based off of username instead of first name or last name. However, if you show the user which one you are going to use (possibly by showing their username, email, etc) then it could work.