Let's say I have a model
class A < ApplicationRecord
serialize :vals, Array
end
which stores an array of values. How can I dynamically populate a list of form values? My first guess was to write
<%= @a.vals.each_with_index do |v, i| %>
<%= f.text_field :hints %>
<% end %>
but this is giving me errors.
Submitting this form
passes
"a"=>{"vals"=>["first", "second", "third"]}
in the params to the controller.As mentioned in the comments, you want to look at the
vals
from an instance ofA
not the classA
.Note about the
serialize
(more for the comments saying it looks wrong) I had never used it, thatserialize :vals, Array
seems to be working for me