Two models, Organization and User, have a 1:many relationship. I have a combined signup form where an organization plus a user for that organization get signed up.
The p
organization has_many :users and user belongs_to :organization
organization.rb
accepts_nested_attributes_for :users
new.html.erb
<%= form_for @organization, url: next_url do |f| %>
<%= render 'shared/error_messages', object: @organization %>
<%= f.text_field :name %>
# Other fields
<%= f.fields_for(:users,@organization.users.build) do |p| %>
<%= p.email_field :email %>
# Other fields
<% end %>
<%= f.submit "Submit" %>
<% end %>
In controller
def create
@organization = Organization.new(new_params)
if @organization.save
flash[:success] = "Yeah!"
redirect_to root_url
else
render :new
end
end