title: How to create child records in partent new view Ruby On Rails
body: <p>Basically what I want to do is create child records(in this case Timetables) of a parent model (In this case Pins that represent some subjects to be published) in the new view. I am using the simple_form gem in order to create the new Pins. my partial form view looks like:</p>
  
  <pre><code>    = simple_form_for @pin, html: {multipart: true} do |f|
        - if @pin.errors.any?
          #errors
            %h2
            = pluralize(@pin.errors.count, "error")
            prevented this Pin from saving
            %ul
              - @pin.errors.full_messages.each do |msg|
                %li= msg
  
        .form_group
          = f.input :image, input_html: {class: 'form_control'}
        .form_group
          = f.input :title, input_html: {class: 'form_control'}
        .form_group
          = f.input :description, input_html: {class: 'form_control'}
        .form_group
          = f.collection_select :category_id, Category.all, :id, :name, {prompt: "Escoge una Categoría"}
        %br/
        .form_group
          = f.label "Seleccione para que aparezca en las novedades de la pagina de inicio"
        .form_group
          = f.check_box :index, class: "check"
        %br/
          = f.button :submit, class: "btn btn-primary"
  </code></pre>
  
  <p>This is my pin.rb model:</p>
  
  <pre><code>     class Pin &lt; ActiveRecord::Base
          belongs_to :category
          has_many :timetables
          acts_as_votable
          has_attached_file :image, styles: { medium: "300x300&gt;"}
          validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
          validates :title, presence: true
          validates :description, presence: true
       end
  </code></pre>
  
  <p>And the timetable.rb model is:</p>
  
  <pre><code>    class Timetable &lt; ActiveRecord::Base
        belongs_to :pin
      end
  </code></pre>
  
  <p>My view looks like this: <a href="https://i.stack.imgur.com/IrbC2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IrbC2.png" alt="enter image description here"></a></p>
  
  <p>So in the red Line I want to offer the user to create different timetables records before pressing the Create Pin button, then when the button is preseed the timetables records are created as well as the pin record, both are associated througn a pin_id column that the timetables table has:</p>
  
  <p><a href="https://i.stack.imgur.com/xXxAw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xXxAw.png" alt="enter image description here"></a></p>
  
  <p>I know that there is an option where a new attribute for the Pins table is created and the data is saved in an array format but I want to do it using 2 models a parent and a child, I do not know if that is possible? Please help me with any suggestion if you know any solution for my problem.</p>
  
  <p>I have been trying with this method: <a href="https://www.sitepoint.com/complex-rails-forms-with-nested-attributes/" rel="nofollow noreferrer">https://www.sitepoint.com/complex-rails-forms-with-nested-attributes/</a>, but apparently it only allows me to edit the records once they are already created. I tried to modify that code in order to create both at once when the button was created but I could not do it, Maybe you can do something with that information. </p>
  
  <p>Many thanks in advance</p>