Form helper: attribute as an array


I have a model with an attribute called “degrees”. This attribute is
serialized. The attribute has to store an array like this:
[“degree1”, “degree”]

My question is, how can I do this in my form?

I have done this but I only get the last element
<% form @obj do |f| %>
<%=f.check_box :degree, “degree1” %>
<% end %>



On Mon, Sep 5, 2011 at 9:32 PM, Gregory Ma [email protected] wrote:

<%=f.check_box :degree, “degree1” %>
<% end %>

i’m assuming you have a list of degrees which the user can check.
upon submitting the form, you want params[:obj][:degree] to be
an array with values equal to the checked degrees. if that’s right
then you need to use check_box_tag

<% [‘degree1’, ‘degree2’, ‘degree3’].each do |degree| %>
<%= check_box_tag ‘obj[degree][]’, degree %>
<% end %>


[email protected].
For more options, visit this group at