views:

34

answers:

1

Take a model with an attribute that is an array of strings. This attribute is serialized to the database.

class MyModel < ActiveRecord::Base
  serialize :str_array
end

In the edit view I would like to display a text field for each element of the array allowing the user to view and modify the attributes elements.

+1  A: 

Not up on my haml syntax, but this should get you going:

# form

<% form_for :my_model do |f| %>

<% render :partial => 'str_field', :collection => @my_model.str_array %>

<% end %>

# _str_field partial:

<input type="text" value="<%=str_field-%>" name="my_model[str_array][]" />

There is also a str_field_counter variable that may be of use for you.

You can definitely customize to your basic situation, but that is the basics.

Alan Peabody