Ask A Question


You’re not receiving notifications from this thread.

How do I save the user_id by adding the mail?

Nicolás Bobb asked in Rails

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

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 76,990+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.