title: RoR duplication fields
body: <p>When an incorrect mandatory fields, the page reloads and you receive an incorrect entry fields and all fields in the form company_form duplicated.</p>
  
  <p>User model(user.rb):</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    ....
    has_many :companies, :autosave =&gt; true
    accepts_nested_attributes_for :companies
    has_and_belongs_to_many :roles
    def role?(role_name)
      return !!self.roles.find_by_name(role_name)
    end
    def with_company
      self.companies.build
      self
    end
  end
  </code></pre>
  
  <p>Company model:</p>
  
  <pre><code>class Company &lt; ActiveRecord::Base
    ...
    belongs_to :user
    ...
  end
  </code></pre>
  
  <p>views/devise/registration/new.html.haml:</p>
  
  <pre><code>= form_for(resource.with_company, :as =&gt; resource_name, :url =&gt; registration_path(resource_name), :html =&gt; { :class =&gt; 'form-horizontal'}) do |f|
  ...
    = f.fields_for :companies do |company_form|
    ...
  ...
  </code></pre>