I have the following model:
class Deck < ActiveRecord::Base
has_many :cards
serialize :stats
attr_accessible :name, :description, :stats
end
In this, stats should be an array of strings. I want to be able to add an arbitrary number of stats to the row (using javascript to add additional “stat” input boxes, but that is outside the scope if the question.)
My question is how do I reflect this structure in the view? If I was building the form manually then it would look like:
<input type="text" name="deck[stats][]">
My view currently looks like:
<%= f.fields_for :stats, @deck.stats do |p| %>
<%= p.label :p, "Stats: " %>
<%= p.text_field :p %>
<% end %>
But this outputs:
<input type="text" name="deck[stats][p]">
I also want a counter so I can display the label as “Stat 1:”, “Stat 2:”, etc.
Any help is appreciated.
Posting the solution I went for to aid future readers.