Hidden_field_tag flattens my array for value

ERB:
<%= hidden_field_tag(‘users_ids’, @users.collect(&:id))%>

OUTPUT:

I want to grab an array of user ids and then do something with them, but
hidden_form_tag is flattening my array. I’ve tried various ways of
putting an array into h_f_t and it always flattens it. How can I
preserve the structure of my array?

Try this:

<% for user in @users %>
<%= hidden_field_tag “user_id[]”, user.id %>
<% end %>

Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)

On Sat, Jan 10, 2009 at 8:35 PM, Taylor S.

Maurício Linhares wrote:

Try this:

<% for user in @users %>
<%= hidden_field_tag “user_id[]”, user.id %>
<% end %>

This worked perfectly. Thank you.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs