I’m trying to create a dynamic set of text fields as follows:
<% for i in 0…count%>
<input id=“<%=“notes_#{i}”%>” name=“<%=“notes[#{i}]”%>” type=“text” size=“65” maxlength=“55” value=“”/>
<%end%>
In the controller, I grab the contents of params[:notes] and loop through them. From what I see, :notes is not an Array but a Hash (ex: “1”=>“test1”, “3”=>“test3”, “2”=>“test2”)
How do I write notes in rhtml as an array and not a hash? I need to preserve order.
If, on the other hand, you want to pass an array to a view for Rails to use in creating a new page, you'd create an instance variable of type Array in your controller and then reference it in the view (.rhtml) file. If by "preserve order" you mean you need to render the text boxes visually from top to bottom by index, you'll want to iterate through the array (e.g., @notes.each) in your view and render a partial for each element.