title: 3 or more level nested forms Rails 4 - SImple Form
body: <p>I need to create a form with several models, at least five. At the moment I am trying to make it work using three forms (Person - Diseases - Treatments). The second first and second level forms work correctly. The third form doesn't even render in my view. Can somebody help me with this? Thanks in advance!!!.</p>
  
  <p><strong>Form</strong></p>
  
  <pre><code>&lt;%= simple_form_for @person, :html =&gt; { id: "smart-form-register" , class: "smart-form client-form" } do |f| %&gt;
  
      &lt;header&gt;
          Por favor, completa el formulario
      &lt;/header&gt;
  
      &lt;fieldset&gt;
          &lt;h2&gt;Datos de contacto e información general&lt;/h2&gt;&lt;br&gt;
          &lt;section&gt;
              &lt;label class="input"&gt;
                  &lt;%= f.input :phone, label: 'Teléfono' %&gt;
          &lt;/section&gt;
          &lt;div class="row"&gt;
              &lt;section class="col col-2"&gt;
                  &lt;%= f.input :name, :input_html =&gt; { :value =&gt; current_user.name}, :as =&gt; :hidden %&gt;
              &lt;/section&gt;
              &lt;section class="col col-2"&gt;
                  &lt;%= f.input :lastname, :input_html =&gt; { :value =&gt; current_user.lastname}, :as =&gt; :hidden %&gt;
              &lt;/section&gt;
              &lt;section class="col col-6"&gt;
                  &lt;%= f.input :email, :input_html =&gt; { :value =&gt; current_user.email}, :as =&gt; :hidden %&gt;
              &lt;/section&gt;
          &lt;/div&gt;
      &lt;/fieldset&gt;
  
          &lt;%= f.simple_fields_for :diseases do |my_disease| %&gt;
  
              &lt;fieldset&gt;
                  &lt;h2&gt;¿Padeces alguna enfermedad?&lt;/h2&gt;&lt;br&gt;
                  &lt;section&gt;
                      &lt;label class="input"&gt;
                          &lt;%= my_disease.input :name, label: 'Nombre de la enfermedad' %&gt;
                  &lt;/section&gt;
                  &lt;div class="row"&gt;
                      &lt;section class="col col-6"&gt;
                          &lt;%= my_disease.input :start, :as =&gt; :date_picker, label: 'Inicio de la enfermedad' %&gt;
                      &lt;/section&gt;
                      &lt;section class="col col-6"&gt;
                          &lt;%= my_disease.input :end, :as =&gt; :date_picker, label: 'Fin de la enfermedad' %&gt;
                      &lt;/section&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                      &lt;section class="col col-6"&gt;
                          &lt;%= my_disease.input :chronical, as: :boolean, :html =&gt; {type: "checkbox" }, label: false, inline_label: 'Enfermedad crónica' %&gt;
                      &lt;/section&gt;
                      &lt;section class="col col-6"&gt;
                      &lt;span class=""&gt;
                          &lt;%= my_disease.input :unfinished, as: :boolean, :html =&gt; {type: "checkbox" }, label: false, inline_label: 'Enfermedad actual' %&gt;
                      &lt;/span&gt;
                      &lt;/section&gt;
                  &lt;/div&gt;
                  &lt;section&gt;
                              &lt;%= my_disease.input :description, label: 'Descripción de la enfermedad' %&gt;
                  &lt;/section&gt;
              &lt;/fieldset&gt;
  
              &lt;fieldset&gt;
                  &lt;section&gt;
                          &lt;%= my_disease.simple_fields_for :treatments do |my_treatment| %&gt;
                                  &lt;%= my_treatment.input :name, label: 'Nombre del tratamiento' %&gt;
                          &lt;% end %&gt;
                  &lt;/section&gt;                      
              &lt;/fieldset&gt;
  
          &lt;% end %&gt;
  
      &lt;footer&gt;&lt;button type="submit" class="btn btn-primary"&gt;Register&lt;/button&gt;&lt;/footer&gt;
  
  &lt;% end %&gt; 
  </code></pre>
  
  <p><strong>Person Controller</strong></p>
  
  <pre><code>def person_params
    params.require(:person).permit(:name, :surname, :gender, :birthdate, :bloodtype, :user_id, :phone, :email, diseases_attributes: [:id, :name, :description, :start, :end, :chronical, :description, :unfinished, treatments_attributes: [:id, :name]] )
  end
  </code></pre>
  
  <p><strong>Diseases Controller</strong></p>
  
  <pre><code>def disease_params
    params.require(:disease).permit(:name, :start, :end, :chronical, :unfinished, :description, :person_id, :person_id, treatments_attributes: [:id, :name] )
  end
  </code></pre>
  
  <p><strong>Diseases Model</strong></p>
  
  <pre><code>class Disease &lt; ActiveRecord::Base
    belongs_to :person
    has_many :treatments
    # validates_presence_of :name, :start
    # validates :name, :length =&gt; {:maximum =&gt; 50, :too_long =&gt; "is too long, you can use the description field"}
    # validate :start_must_be_before_end, :unless =&gt; [:chronical, :unfinished], :presence =&gt; true
    # validates :end, :presence =&gt; true, :unless =&gt; [:chronical, :unfinished], :presence =&gt; true
    # validates :description, :length =&gt; {:maximum =&gt; 5000, :too_long =&gt; "is too long"}
  
    accepts_nested_attributes_for :treatments
  
    def start_must_be_before_end
      if self[:end] &lt; self[:start]
        errors.add(:start, "must be before end time")
        return false
      else
        return true
      end
    end
  
  end
  </code></pre>
  
  <p><strong>Person Model</strong></p>
  
  <pre><code>class Person &lt; ActiveRecord::Base
        belongs_to :user
        has_many :diseases, :dependent =&gt; :destroy #if you delete a person you also delete all diseases related
        has_many :appointments, :dependent =&gt; :destroy
        has_many :treatments, through: :diseases
        validates_presence_of :name, :email
        validates :name, :length =&gt; {:maximum =&gt; 50, :too_long =&gt; "name is too long"}
        VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
        validates :email, format: { :with =&gt; VALID_EMAIL_REGEX , message: "is invalid" }
  
        accepts_nested_attributes_for :diseases
        accepts_nested_attributes_for :treatments
  
      end
  </code></pre>
  
  <p><strong>Terminal</strong></p>
  
  <pre><code>  User Load (0.8ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 60 ORDER BY "users"."id" ASC LIMIT 1
  Unpermitted parameters: treatments
     (0.2ms)  BEGIN
    SQL (0.7ms)  INSERT INTO "people" ("created_at", "email", "name", "phone", "surname", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["created_at", Fri, 13 Jun 2014 14:17:12 UTC +00:00], ["email", "danielcastillomarfull@gmail.com"], ["name", "Daniel"], ["phone", "123123"], ["surname", "Castillo"], ["updated_at", Fri, 13 Jun 2014 14:17:12 UTC +00:00], ["user_id", 60]]
    SQL (0.6ms)  INSERT INTO "diseases" ("chronical", "created_at", "description", "end", "name", "person_id", "start", "unfinished", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"  [["chronical", false], ["created_at", Fri, 13 Jun 2014 14:17:12 UTC +00:00], ["description", ""], ["end", Fri, 13 Jun 2014], ["name", "desidia"], ["person_id", 161], ["start", Thu, 12 Jun 2014], ["unfinished", false], ["updated_at", Fri, 13 Jun 2014 14:17:12 UTC +00:00]]
     (51.7ms)  COMMIT
  </code></pre>