Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>accepts_nested_attributes_for</code> in your User model (<a href="http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html" rel="noreferrer">documentation</a>)</p> <p>It should look like:</p> <pre><code>class User &lt; ActiveRecord::Base belongs_to :organization accepts_nested_attributes_for :organization end class Organization &lt; ActiveRecord::Base has_many :users end </code></pre> <p>In views you could use Rails helper or create field by hand:</p> <pre><code>&lt;input type="text" name="user[organization_attributes][name]"&gt; &lt;% user = User.new(organization =&gt; Organization.new) %&gt; &lt;%= form_for user do |form| %&gt; &lt;%= form.fields_for user.organization do |organization_form| %&gt; &lt;%= organization_form.text_field :name %&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <p>EDIT: Your devise view should look like:</p> <pre><code>&lt;h2&gt;Sign up&lt;/h2&gt; &lt;% resource.organization ||= Organization.new %&gt; &lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt; &lt;%= devise_error_messages! %&gt; &lt;div&gt;&lt;%= f.label :email %&gt;&lt;br /&gt; &lt;%= f.email_field :email %&gt;&lt;/div&gt; &lt;%= f.fields_for resource.organization do |organization_form| %&gt; &lt;div&gt;&lt;%= organization_form.label :name %&gt;&lt;br /&gt; &lt;%= organization_form.text_field :name %&gt;&lt;/div&gt; &lt;% end %&gt; &lt;div&gt;&lt;%= f.label :password %&gt;&lt;br /&gt; &lt;%= f.password_field :password %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.label :password_confirmation %&gt;&lt;br /&gt; &lt;%= f.password_field :password_confirmation %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.submit "Sign up" %&gt;&lt;/div&gt; &lt;% end %&gt; &lt;%= render :partial =&gt; "devise/shared/links" %&gt; </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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