Skip to main content

How do I save the user_id by adding the mail?

Rails • Asked by Nicolás Bobb

How do I save the user_id by adding the mail?

For the relationship, you have to save the user_id, but to be more dynamic for the user, I want to the users search other users by the email and rails save the id as usual.

How is it done?

In the views I have:

 <div class = "field">
     <% = form.label: user_id%>
     <% = form.text_field: user_id, id%>
   </ div>

 I'm using Devise.


Some ideas to get you going. Add an input field for the email, eg <% = email_field_tag :email %>.

In the controller (create) action, you can find by email, eg: user = User.find_by(email: params[:email]).

This is just the basics and should help you move forward. Just let us know if you need more guidance after you tried this.


Thanks Jack! As you said, I solve it


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.