Note that there are some explanatory texts on larger screens.

plurals
  1. PORails need to pass field to model before_create
    primarykey
    data
    text
    <p>I have Employees, Contacts and Users. When a new Contact or Employee is created, their respective model creates a new User. These are the relations:</p> <pre><code> Contact belongs_to :user Employee belongs_to :user User has_one :contact User has_one :employee </code></pre> <p>Right now I've got an email field in all 3 tables. But, I'd like to remove the email field from the Contact and Employee and only use the User.email.</p> <p>Currently the Contact Model code is this:</p> <pre><code>before_create :create_user protected def create_user self.user = User.create({ :email =&gt; self.email, :password =&gt; 'password' }) return user.save end </code></pre> <p>The Contact form has this:</p> <pre><code> &lt;%= f.input :email %&gt; </code></pre> <p>How can I get the email into the Contact form and pass it to the Contact controller to put into the new User record?</p> <p>Thanks for the help!</p> <p>UPDATE1</p> <p>I tried this, but it didn't work:</p> <p>Contact Form:</p> <pre><code> &lt;%= text_field_tag :email %&gt; </code></pre> <p>Contact Controller:</p> <pre><code> protected def create_user self.user = User.create({ :email =&gt; params[:email], :password =&gt; '123456' }) return user.save end </code></pre> <p>UPDATE 2</p> <p>I tried this, but it doesn't work:</p> <p>Contact Form:</p> <pre><code> &lt;%= params[:email] = email_field_tag 'email'%&gt; </code></pre> <p>Contact Controller:</p> <pre><code> before_create :create_user protected def create_user self.user = User.create({ :email =&gt; params[:email], :password =&gt; '123456' }) return user.save end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload