Using after_action to create account after a Devise registration for rails
<p>Done a lot of reading on the situation below. Want some opinions.</p>

<p>In the thread at (1) the user asks "How to create another object when creating a Devise User from their registration form in Rails?". This is exactly what I am trying to do as well. When a user registers I want to create an Account object.</p>

<p>(1) <a href="https://stackoverflow.com/questions/15619951/how-to-create-another-object-when-creating-a-devise-user-from-their-registration">How to create another object when creating a Devise User from their registration form in Rails?</a></p>

<p>However there's a problem I've been having, which also surfaced at the referenced thread. When I run the following in my subclassed registrations controller. I get "When assigning attributes, you must pass a hash as an argument." ArgumentError in RegistrationsController#create.</p>

<pre><code>class RegistrationsController &lt; Devise::RegistrationsController
    after_action :create_account, only: [:create, :update]


    private
    def create_account
        Account.create(@user)
    end
end
</code></pre>

<p>It turns out that using callbacks don't work because I don't have access to the params hash. I've tried so many different variations of the Account.create(current_user) or (@user) as well as adding another def below to try to permit the user id param to go to user_id foreign key of Account. Still the same error "When assigning attributes, you must pass a hash as an argument."</p>

<pre><code>def account_params
    params.require(:account).permit(:user_id,:user)
end
</code></pre>

<p>This is where the question at (1) ended up. It proposed bypassing Devise's RegistrationsController.</p>

<p>Is this the only remaining way to achieve the objective of creating other models when a User registers in Devise? Any other suggestions? I don't want to commit to bypassing the registrations controller unless its the only way.</p>

<p>Thanks for any suggestions and happy to provide any other information.</p>

<pre><code>class Account &lt; ApplicationRecord
    has_many :users
end

class User &lt; ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  has_many :projects
  has_many :notes
  belongs_to :account
</code></pre>