I have an application which keeps track of my financial data. Each bank transaction I make is stored as an Entry model. An entry just has a name and an amount. I keep the text_field for name and amount inside of a partial called _entry.haml
I have a separate page for creating a new entry and editing an entry, both using this partial. The edit page correctly pre-populates the name and amount fields.
I want to add the ability for my app to import entries from a csv. In step one, I select the file and click go. In step two, I receive the file in my controller via @parsed_file = CSV::Reader.parse(params[:csvfile]) I iterate through parsed_file and create an array of Entries like so: counter = 0 @parsed_file.each do |row| entry = Entry.new entry.description = row[1] entry.amount = row[3] @csvdata[counter] = entry counter += 1 end
In my view I iterate over the @csvdata array: - for entry in @csvdata %div= render :partial => "entry/entry", :locals => { :entry => entry }
The entry partial is rendered, however, the entries are not pre- populated! The names given to all my HTML Form elements are the same!
1) How do I get the partials to pre-populate my form elements? 2) If I wrap all these form elements into a form, how would I process them when the next controller action receives this data?
Thank you for any information you can give!