davissp14
davissp14

Reputation: 765

Name array in Rails 3

I have been searching around for a solution for quite some time, hoping someone could point me to an answer or alternative solution...

I am looking to implement a input name array using the Rails form helpers.

So traditionally in html, I would just write something like this:

<input type="text" name="email[]" value="blah" />
<input type="text" name="email[]" value="blah2" />

Does anyone know how an array like this can be achieved using rails helpers? { Doesnt work }

<%= f.text_field :email[] %>
<%= f.text_field :email[] %>

I appreciate it!

Upvotes: 0

Views: 809

Answers (1)

Mario Visic
Mario Visic

Reputation: 2663

You can use the form tag helpers to create the inputs you want.

= text_field_tag 'email[]', 'blah'
= text_field_tag 'email[]', 'blah2'

See here http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html for more info.

To use text_field instead of the tag version your modem would need to respond to the email[] method.

Upvotes: 3

Related Questions