Adding HABTM association while creating a record

Hello Experts,
I have a HABTM association as followed:

class Account < ActiveRecord::Base
has_and_belongs_to_many :user

class User < ActiveRecord::Base
has_and_belongs_to_many :type
has_and_belongs_to_many :account

class Type < ActiveRecord::Base
has_and_belongs_to_many :user

I have the following query;
I Have a parent user who is creating another user under its account.
How can i add association record between the new user (that is getting
added) and the parent user’s account.
my form is as followed:

<%= f.label :username %>
<%= f.text_field :username %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>

<% for type in Type.find(:all) %>

<%= check_box_tag “user[type_ids][]”,,
@user.type.include?(type) %>
<%= type.type_name %>

<% end %>
<%= f.submit %>

Thanks in advance for any guidelines.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs