My nested attribute form is adding unwanted fields automatically each time I save my regular form.
How do I prevent from adding an extra field after saving?
registrations_controller.rb controller
def edit
@user = User.find(current_user.id)
@profile = Profile.new
@user.businesses.build
end
business.rb model
class Business < ActiveRecord::Base
belongs_to :users
end
user.rb model
class User < ActiveRecord::Base
has_many :businesses
end
view page
<%= form_for @user, :html => {:multipart => true} do |f| %>
<%= f.fields_for :businesses do |builders| %>
<%= builders.text_field :name %>
<% end %>
<%= f.submit "Save" %>
<% end %>
At first it shows a single empty field, and then when I press save, it adds another one, even though if its blank or not. I just want to keep one field for now and not automatically add another one.