You are pretty close.
The trick is that both forms should be nested in a form that represents them, which should be a different model. I do not know how your application is put together, but I will assume that Patients have many Processes. Your models should include the following:
patient.rb
attr_accessible :treatments_attributes, etc... has_many :treatments accepts_nested_attributes_for :treatments
treatment.rb
belongs_to :patient
As you can see, the patient accepts attributes for the procedures (thus, the third and first row in this model). Thus, you really need to wrap the patient-shaped forms of treatment so that you submit the patient's form using your nested procedures. Something like that:
<%= form_for @patient do |f| %> <%= f.fields_for @patient.build_treatment do |tf| %> <%= render 'treatment_form', locals: { form: tf } %> <% end %> <%= f.fields_for @patient.build_treatment do |tf| %> <%= render 'treatment_form', locals: { form: tf } %> <% end %> <%= f.submit %> <% end %>
So, you have this form for the patient , which represents both forms of treatment automatically associated with the patient. I may have messed up some of the features, but this is the main idea.
EDIT - you can check this option . It is best to place the building processing the shape of the objects in your controller, as they do in this matter. And you can check the Rails API for more specific help on accepts_nested_attributes_for.
In addition, if it is unclear, the thing "locals" simply passes the object of the processing form to a partial variable under the form "form", therefore in this partial file you should write <% = form.label: regardless of%> ... and t .d., inside this partial.
If you create form objects in the controller -
@patient.build_treatments
- then you can do this in your view:
<%= f.fields_for :treatment do |tf| %>
Also, if this is not clear , your partial will look something like this: based on your code:
<table width="100%"> <tr> <th><%= form.collection_select :category_id, Category.find(:all), :id, :typ %></th> <th><%= form.text_field :content , :id => "inputbox"%></th> <th><%= form.text_field :day, :value => Date.today %></th> </tr> </table>
Another layout that may be more intuitive:
main view
<%= form_for @patient do |f| %> <%= render 'treatment_form', form: f %> <% end %>
partial view
<%= form.fields_for :treatment do |field| %> <% field.label :whatever %>
In other words, you would move the call to fields_for inside the partial, which could make more sense. Actually, you should not change how everything works.