Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Devise registration with an additional model
    text
    copied!<p>I've searched for about an hour now and found an immense amount of questions describing how to add fields to the Devise user model. However I couldn't find any that explain in a clear way how to add one or multiple models to the registration process.</p> <p>At registration I want the user to fill out an e-mailaddress, password and in addition my client model, company model and address model (so I have all the information the webapplication needs to run properly).</p> <p>My models are like this</p> <p><strong>user.rb</strong></p> <blockquote> <pre><code>class User &lt; ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable attr_accessible :email, :password, :password_confirmation, :remember_me, :client belongs_to :client end </code></pre> </blockquote> <p><strong>client.rb</strong></p> <blockquote> <pre><code>class Client &lt; ActiveRecord::Base attr_accessible :bankaccount, :email, :logo, :mobile, :phone, :website has_many :users has_one :company has_one :address accepts_nested_attributes_for :company, :address end </code></pre> </blockquote> <p>I think the only way to do this is to create my own RegistrationsController so I can do <code>@client = Client.new</code> and then do this in my view:</p> <blockquote> <pre><code> &lt;%= f.simple_fields_for @client do |ff| %&gt; &lt;%= f.simple_fields_for :company do |fff| %&gt; &lt;% field_set_tag t(:company) do %&gt; &lt;%= ff.input :name %&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;%= f.simple_fields_for :address do |fff| %&gt; //address inputs &lt;% end %&gt; &lt;% end %&gt; &lt;fieldset&gt; &lt;legend&gt;&lt;%= t(:other) %&gt;&lt;/legend&gt; // other inputs &lt;/fieldset&gt; &lt;% end %&gt; </code></pre> </blockquote> <p>The reason I need it to work this way is because I have multiple users who can represent the same client (and thus need access to the same data). My client owns all the data in the application and therefor needs to be created before the application can be used.</p>
 

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