You’re not receiving notifications from this thread.
How do I sort fields for and include a new fields for entry?
Sorry for the confusing question, I couldn't think of a better way to phrase it.
I have a 'Prospect' model that accepts nested attributes for 'prospect_calls'. When editing the prospect I need to see all the prospect calls in the order that they were made and be able to add a new prospect call if required.
In the controller I have the following code,
@prospect.prospect_calls.build call_date: @required_date
This adds a new call record that can be edited or ignored by the user. In the prospect model I reject prospect calls if the "who" field on the call record is not entered. This all works perfectly if the calls are not sorted. If they are sorted the new call record does not appear in the call list on the edit view.
To sort the calls I have included the following in the view,
<%= form.fields_for :prospect_calls, form.object.prospect_calls.order(:call_date) do |p| %>
This sorts the calls perfectly, but the new call record does not appear in the list of calls.
How can I sort the call records and have a new call record on the edit view?