Hello Experts,
I have a HABTM association as followed:
class Account < ActiveRecord::Base
has_and_belongs_to_many :user
end
class User < ActiveRecord::Base
has_and_belongs_to_many :type
has_and_belongs_to_many :account
end
class Type < ActiveRecord::Base
has_and_belongs_to_many :user
end
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.text_field :username %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
<%= f.password_field :password_confirmation %>
<% for type in Type.find(:all) %>
<%= check_box_tag “user[type_ids][]”, type.id,
@user.type.include?(type) %>
<%= type.type_name %>
<% end %>
<%= f.submit %>
Thanks in advance for any guidelines.