How to add fields dynamically?

I would like have a simple interface for users to add data into
database. How to add new textareas in form, until user want it and
submit all of them at once?

Aa Sh wrote:

I would like have a simple interface for users to add data into
database. How to add new textareas in form, until user want it and
submit all of them at once?

Look up how to serialize a Hash into a :text field.

If you don't need to query a database by a field, you don't need the full overhead of a field type. To give your users abstract data, let them enter keys and values into fields that expand forever, and then AR will serialize them. They go in as YAML strings of your hashes.

Aa Sh wrote:

I would like have a simple interface for users to add data into
database. How to add new textareas in form, until user want it and
submit all of them at once?

However, if you _do_ need to look these strings up in the database, you need a child table with a parent_id, and key and value fields!

http://railscasts.com/episodes/73-complex-forms-part-1

http://railscasts.com/episodes/74-complex-forms-part-2

… and everything on railscasts.com basically

Best regards

Peter De Berdt

Peter De Berdt wrote:

I would like have a simple interface for users to add data into
database. How to add new textareas in form, until user want it and
submit all of them at once?

http://railscasts.com/episodes/73-complex-forms-part-1
http://railscasts.com/episodes/74-complex-forms-part-2
  ... and everything on railscasts.com basically

Best regards

Peter De Berdt

Thank you so much, it is almost exactly what I need, except I am a
novice in RoR, so I can't change the example from multi models to simple
one. I try, but have an error.

Now I have table in database with "e_key" and "comment" fields and
standard new.html.erb (built by scaffolding). So actually I have two
question:
1) How dynamically to add empty fields on page (by click button)?
2) How to collect all data from all rows and put they into database?

Thank you for your time!

Phlip, Peter, and Bharat,

Thank you for advises and your time!

Aa Sh wrote:

Phlip, Peter, and Bharat,

Thank you for advises and your time!

I did it!