TAGS :Viewed: 7 - Published at: a few seconds ago

[ Rails releationship between form and DB ]

I have a text field in my rails form. How would I be able to allow users to enter a set or comma separated values, for example "12343, 121223, 32212", and store these strings in the database on new rows so that I can easily perform distinct counts on this field.

Answer 1

you can split the field value:

values = param[:field_name].split(', ')
values.each do |v|
  Model.create(:column_name => value)

I'm not sure if I understood right, your question is not really precise