I am wondering if it is possible to create a custom sql to be used within a fields_for and when editing avoid duplicates or if I should build my custom query and loop through the results in a different way.
The reason I am asking is because I have nested attributes that only need a text field named "suggested amount" and a text area named "comments" as many times as resources I have, but within the fields_for I need to display the resource name for each resource_id and another resource amount coming from a different table. I was thinking of something like this:
<fields_for :reviewer_resources > <table> resource_name, pi_requested_amount, text_field for suggested_amount, text_area for comments </table> <end>
when saving for the first time it will create the suggested_amount for each resource_id, but I am wondering how to approach the Edit part since fields_for will bring the existing children and I also need to build suggested_amount and comments for the other resources that were not chosen. If my custom query includes the suggested_amount and comments too, do I need fields_for at all?.
Is this doable or should I approach it in a different way?.
I've been struggling with this for weeks now so any help is much appreciated.
Edited by Jamie, 21 August 2013 - 05:02 PM.
Code tags added